aboutsummaryrefslogtreecommitdiffstats
path: root/tools/profile
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2015-06-01 18:13:12 -0500
committerschneems <richard.schneeman@gmail.com>2015-06-01 19:44:40 -0500
commite1a7260640295642108a364c2cfa56b6868d9947 (patch)
tree4ed87c1b0fd924b8a53d302c75a03cc751caa7dd /tools/profile
parentf7c0d133f982e4607c8b78e13fef6edafa7eb590 (diff)
downloadrails-e1a7260640295642108a364c2cfa56b6868d9947.tar.gz
rails-e1a7260640295642108a364c2cfa56b6868d9947.tar.bz2
rails-e1a7260640295642108a364c2cfa56b6868d9947.zip
Use block variable instead of global
```ruby require 'benchmark/ips' Benchmark.ips do |x| x.report("$&") { "foo".sub(/f/) { $&.upcase } } x.report("block var") { "foo".sub(/f/) {|match| match.upcase } } end ``` ``` Calculating ------------------------------------- $& 48.658k i/100ms block var 49.666k i/100ms ------------------------------------------------- $& 873.156k (± 9.3%) i/s - 4.331M block var 969.744k (± 9.2%) i/s - 4.818M ``` It's faster, and gets rid of a few "magic" global variables
Diffstat (limited to 'tools/profile')
-rwxr-xr-xtools/profile4
1 files changed, 2 insertions, 2 deletions
diff --git a/tools/profile b/tools/profile
index eb7fc7792b..191e73b3dd 100755
--- a/tools/profile
+++ b/tools/profile
@@ -117,9 +117,9 @@ rescue LoadError
def camelize(uppercase_first_letter = true)
string = self
if uppercase_first_letter
- string = string.sub(/^[a-z\d]*/) { $&.capitalize }
+ string = string.sub(/^[a-z\d]*/) { |match| match.capitalize }
else
- string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
+ string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { |match| match.downcase }
end
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
end