summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-21 04:38:40 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-21 04:38:40 +0000
commit5647b2cd881bc45e531a71d51c1b9f9bbee9ce7f (patch)
tree4d4aa019134d1ed6e6f9962fb6955d6a9b3fe21c
parentc618db17ee082b5b125bfea8410214058fc1fe17 (diff)
* lib/uri/common.rb: Have URI#route_to, URI#route_from accept
string-like arguments [ruby-core:30961] * lib/uri/generic.rb: ditto for URI.join, URI#merge git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28699 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--lib/uri/common.rb12
-rw-r--r--lib/uri/generic.rb31
3 files changed, 14 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index 2619a4cc0e..88d5bc1f65 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Wed Jul 21 13:37:35 2010 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
+
+ * lib/uri/common.rb: Have URI#route_to, URI#route_from accept
+ string-like arguments [ruby-core:30961]
+
+ * lib/uri/generic.rb: ditto for URI.join, URI#merge
+
Wed Jul 21 12:39:15 2010 Yusuke Endoh <mame@tsg.ne.jp>
* lib/cmath.rb (CMath#cbrt): cbrt should accept a negative real
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index a41cd678d9..1240e6749c 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -185,13 +185,7 @@ module URI
end
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
+ uris[0] = URI(uris[0], self)
uris.inject :merge
end
@@ -844,11 +838,11 @@ module Kernel
#
# Returns +uri+ converted to a URI object.
#
- def URI(uri)
+ def URI(uri, parser = URI::DEFAULT_PARSER)
if uri.is_a?(URI::Generic)
uri
elsif uri = String.try_convert(uri)
- URI.parse(uri)
+ parser.parse(uri)
else
raise ArgumentError,
"bad argument (expected URI object or URI string)"
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index 4fdfd140fe..f20b2d26e1 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -1,3 +1,4 @@
+
#
# = uri/generic.rb
#
@@ -783,14 +784,7 @@ module URI
# return base and rel.
# you can modify `base', but can not `rel'.
def merge0(oth)
- case oth
- when Generic
- when String
- oth = parser.parse(oth)
- else
- raise ArgumentError,
- "bad argument(expected URI object or URI string)"
- end
+ oth = URI(oth, parser)
if self.relative? && oth.relative?
raise BadURIError,
@@ -854,15 +848,7 @@ module URI
private :route_from_path
def route_from0(oth)
- case oth
- when Generic
- when String
- oth = parser.parse(oth)
- else
- raise ArgumentError,
- "bad argument(expected URI object or URI string)"
- end
-
+ oth = URI(oth, parser)
if self.relative?
raise BadURIError,
"relative URI: #{self}"
@@ -966,16 +952,7 @@ module URI
# #=> #<URI::Generic:0x2020c2f6 URL:/main.rbx?page=1>
#
def route_to(oth)
- case oth
- when Generic
- when String
- oth = parser.parse(oth)
- else
- raise ArgumentError,
- "bad argument(expected URI object or URI string)"
- end
-
- oth.route_from(self)
+ URI(oth, parser).route_from(self)
end
#