Class: String
Instance Method Summary collapse
-
#camelize(first_letter_in_uppercase = true) ⇒ Object
Ripped from Rails Inflectors.
-
#constantize ⇒ Object
Ripped from Rails Inflectors.
Instance Method Details
#camelize(first_letter_in_uppercase = true) ⇒ Object
Ripped from Rails Inflectors
24 25 26 27 28 29 30 31 |
# File 'lib/dm-machinist.rb', line 24 def camelize(first_letter_in_uppercase = true) lower_case_and_underscored_word = self if first_letter_in_uppercase lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } else lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1] end end |
#constantize ⇒ Object
Ripped from Rails Inflectors
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dm-machinist.rb', line 34 def constantize camel_cased_word = self names = camel_cased_word.split('::') names.shift if names.empty? || names.first.empty? constant = Object names.each do |name| constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name) end constant end |