Method: String#snake_case

Defined in:
lib/jrubyfx/utils.rb

#snake_case(ignore_prefix_namespace = false) ⇒ Object

call-seq:

snake_case(ignore_prefix_namespace=false) => string

Converts a CamelCaseString to a snake_case_string

"JavaFX".snake_case #=> "java_fx"

If ignore_prefix_namespace is specified it will strip any preceding modules/classes off front of string before snake casing:

Foo::BigBar #=> "big_bar"

By default it will separate modules with a “/”:

Foo::BigBar #=> "foo/big_bar"


57
58
59
60
61
62
63
64
65
# File 'lib/jrubyfx/utils.rb', line 57

def snake_case(ignore_prefix_namespace=false)
  base = ignore_prefix_namespace ?
           self.gsub(/.*::/, '') : self.gsub(/::/, '/')
  base.
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  downcase
end