Module: Ethon::Extensions::String
- Defined in:
- lib/ethon/extensions/string.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#byteslice(*args) ⇒ String
Return part of the string.
-
#underscr ⇒ String
Convert string to underscore.
Instance Method Details
#byteslice(*args) ⇒ String
Return part of the string.
12 13 14 |
# File 'lib/ethon/extensions/string.rb', line 12 def byteslice(*args) self[*args] end |
#underscr ⇒ String
Convert string to underscore. Taken from activesupport, renamed in order to no collide with it.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ethon/extensions/string.rb', line 26 def underscr word = self.dup word.gsub!('::', '_') word.gsub!(/(?:([A-Za-z\d])|^)(#{/(?=a)b/})(?=\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 |