Module: Evoke::Inflections::Underscore
- Defined in:
- lib/evoke/inflections/underscore.rb
Overview
String inflections for converting to underscored form.
Underscoring a string injects an underscore between CamelCase words, replaces all ‘::’ with ‘/’ and converts the string to lowercase. For example, the string “HelloWorld” is underscored to “hello_world”, and the string “Hello::World” is underscored to “hello/world”.
Instance Method Summary collapse
-
#underscore ⇒ String
Creates an underscored, lowercase form of the string and changes ‘::’ to ‘/’ to convert namespaces to paths.
-
#underscore! ⇒ String
Replaces the existing String instance with its underscored form.
Instance Method Details
#underscore ⇒ String
Creates an underscored, lowercase form of the string and changes ‘::’ to ‘/’ to convert namespaces to paths.
18 19 20 21 22 23 24 25 26 |
# File 'lib/evoke/inflections/underscore.rb', line 18 def underscore dup.tap do |s| s.gsub!(/::/, '/') s.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') s.gsub!(/([a-z\d])([A-Z])/, '\1_\2') s.tr!('-', '_') s.downcase! end end |
#underscore! ⇒ String
Replaces the existing String instance with its underscored form.
37 38 39 |
# File 'lib/evoke/inflections/underscore.rb', line 37 def underscore! replace(underscore) end |