Class: String
- Defined in:
- lib/killbill.rb,
lib/killbill/helpers/active_merchant/core_ext.rb
Overview
Thank you Rails!
Instance Method Summary collapse
Instance Method Details
#camelize(uppercase_first_letter = true) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/killbill/helpers/active_merchant/core_ext.rb', line 3 def camelize(uppercase_first_letter = true) string = to_s if uppercase_first_letter string = string.sub(/^[a-z\d]*/) { $&.capitalize } else string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase } end string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" } string.gsub!('/', '::') string end |
#snake_case ⇒ Object
3 4 5 6 7 8 |
# File 'lib/killbill.rb', line 3 def snake_case return downcase if match(/\A[A-Z]+\z/) gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z])([A-Z])/, '\1_\2'). downcase end |
#to_class ⇒ Object
10 11 12 13 14 |
# File 'lib/killbill.rb', line 10 def to_class self.split('::').inject(Kernel) do |mod, class_name| mod.const_get(class_name) end end |