aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorRoque Pinel <repinel@gmail.com>2015-06-08 21:14:33 -0400
committerRoque Pinel <repinel@gmail.com>2015-06-08 21:27:01 -0400
commitb28b192af194ca63fad6e3cde3b56b78f9132cac (patch)
tree87d6a1f1075caeeb0e31b99be97cc97495da5a68 /activesupport/lib/active_support
parentbbbe1a58e60da079d5d353777561d1c998549571 (diff)
downloadrails-b28b192af194ca63fad6e3cde3b56b78f9132cac.tar.gz
rails-b28b192af194ca63fad6e3cde3b56b78f9132cac.tar.bz2
rails-b28b192af194ca63fad6e3cde3b56b78f9132cac.zip
Use block variable instead of global
```ruby Benchmark.ips do |x| x.report("$&") { "foo".gsub(/f/) { $&.hex } } x.report("block var") { "foo".gsub(/f/) { |match| match.hex } } end ``` ``` Calculating ------------------------------------- $& 23.271k i/100ms block var 24.804k i/100ms ------------------------------------------------- $& 321.981k (± 7.4%) i/s - 1.606M block var 324.949k (± 9.2%) i/s - 1.612M ```
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/core_ext/uri.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/uri.rb b/activesupport/lib/active_support/core_ext/uri.rb
index bfe0832b37..0b2ff817c3 100644
--- a/activesupport/lib/active_support/core_ext/uri.rb
+++ b/activesupport/lib/active_support/core_ext/uri.rb
@@ -12,7 +12,7 @@ unless str == parser.unescape(parser.escape(str))
# YK: My initial experiments say yes, but let's be sure please
enc = str.encoding
enc = Encoding::UTF_8 if enc == Encoding::US_ASCII
- str.gsub(escaped) { [$&[1, 2].hex].pack('C') }.force_encoding(enc)
+ str.gsub(escaped) { |match| [match[1, 2].hex].pack('C') }.force_encoding(enc)
end
end
end