Module: Inflections
- Included in:
- RuboCop::Cop::Airbnb::ClassOrModuleDeclaredInWrongFile, RuboCop::Cop::Airbnb::ConstAssignedInWrongFile, RuboCop::Cop::Airbnb::ModuleMethodInWrongFile
- Defined in:
- lib/rubocop/airbnb/inflections.rb
Overview
String inflections copied over from ActiveSupport
Instance Method Summary collapse
-
#underscore(camel_cased_word) ⇒ Object
Convert Foo::BarBaz to foo/bar_baz.
Instance Method Details
#underscore(camel_cased_word) ⇒ Object
Convert Foo::BarBaz to foo/bar_baz. Copied from ActiveSupport.
5 6 7 8 9 10 11 12 13 |
# File 'lib/rubocop/airbnb/inflections.rb', line 5 def underscore(camel_cased_word) word = camel_cased_word.to_s.dup word.gsub!(/::/, '/') word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') word.tr!("-", "_") word.downcase! word end |