Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/pupa.rb
Overview
ActiveSupport's String methods become bottlenecks once:
- HTTP responses are cached in Memcached
- JSON documents are dumped to Redis
- Redis is pipelined
- Validation is skipped
- The runner is quiet
With these optimizations, in sample scripts, garbage collection and gem requiring take up two-thirds of the running time.
Instance Method Summary collapse
-
#underscore ⇒ Object
Alternatively, check if
inflections.acronym_regex
is equal to/(?=a)b/
.
Instance Method Details
#underscore ⇒ Object
Alternatively, check if inflections.acronym_regex
is equal to /(?=a)b/
.
If so, to skip the substitution, which is guaranteed to fail.
55 56 57 58 59 60 61 62 63 |
# File 'lib/pupa.rb', line 55 def underscore word = gsub('::', '/') # word.gsub!(/(?:([A-Za-z\d])|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" } word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2') word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') word.tr!("-", "_") word.downcase! word end |