diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-07-21 03:32:41 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-07-21 03:32:41 +0000 |
commit | 770af8649a22f721408e75d7d92b5c4323472f28 (patch) | |
tree | 99bc70acdc91c02f649f622ab84032da7003e5ad | |
parent | 9a89e864ea8211561c119052b0fa051a348b0ac7 (diff) | |
download | ruby-770af8649a22f721408e75d7d92b5c4323472f28.tar.gz |
* lib/uri/common.rb: Have URI() and URI.join accept URI objects in addition
to strings. [ruby-core:30960]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/uri/common.rb | 29 |
2 files changed, 25 insertions, 9 deletions
@@ -1,3 +1,8 @@ +Wed Jul 21 12:31:30 2010 Marc-Andre Lafortune <ruby-core@marc-andre.ca> + + * lib/uri/common.rb: Have URI() and URI.join accept URI objects in + addition to strings. [ruby-core:30960] + Wed Jul 21 11:55:06 2010 Nobuyoshi Nakada <nobu@ruby-lang.org> * util.c (ruby_hdtoa): renamed from BSD__hdtoa. diff --git a/lib/uri/common.rb b/lib/uri/common.rb index 58fd422a5d..a41cd678d9 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -184,12 +184,15 @@ module URI end end - def join(*str) - u = self.parse(str[0]) - str[1 .. -1].each do |x| - u = u.merge(x) + def join(*uris) + if uris[0].is_a?(URI::Generic) + elsif uri = String.try_convert(uris[0]) + uris[0] = self.parse(uri) + else + raise ArgumentError, + "bad argument(expected URI object or URI string)" end - u + uris.inject :merge end def extract(str, schemes = nil, &block) @@ -837,11 +840,19 @@ module URI end module Kernel - # alias for URI.parse. + # - # This method is introduced at 1.8.2. - def URI(uri_str) # :doc: - URI.parse(uri_str) + # Returns +uri+ converted to a URI object. + # + def URI(uri) + if uri.is_a?(URI::Generic) + uri + elsif uri = String.try_convert(uri) + URI.parse(uri) + else + raise ArgumentError, + "bad argument (expected URI object or URI string)" + end end module_function :URI end |