Module: String::InflectionMethods

Defined in:
lib/core_ext/string/inflection_methods.rb

Overview

Pure string inflection utilities (dasherize, underscore, camelize). Used via String::Inflectable refinement.

Instance Method Summary collapse

Instance Method Details

#camelize(name) ⇒ Object



20
21
22
23
24
25
# File 'lib/core_ext/string/inflection_methods.rb', line 20

def camelize(name)
  scanner    = StringScanner.new(name.to_s)
  new_string = +""
  append_camelize_token(scanner, new_string) until scanner.eos?
  new_string
end

#dasherize(name) ⇒ Object



10
# File 'lib/core_ext/string/inflection_methods.rb', line 10

def dasherize(name) = name.to_s.tr("_", "-")

#underscore(name) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/core_ext/string/inflection_methods.rb', line 12

def underscore(name)
  scanner    = StringScanner.new(name.to_s)
  new_string = +""
  append_underscore_token(scanner, new_string) until scanner.eos?
  new_string.downcase!
  new_string
end