Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string.rb
Instance Method Summary collapse
Instance Method Details
#numeric? ⇒ Boolean
18 19 20 |
# File 'lib/string.rb', line 18 def numeric? Float(self) != nil rescue false end |
#to_camelcase ⇒ Object
2 3 4 5 |
# File 'lib/string.rb', line 2 def to_camelcase return self if self !~ /_/ && self =~ /[A-Z]+.*/ split('_').map{|e| e.capitalize}.join end |
#to_camelcase_lower ⇒ Object
7 8 9 |
# File 'lib/string.rb', line 7 def to_camelcase_lower self.split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join end |
#to_snakecase ⇒ Object
11 12 13 14 15 16 |
# File 'lib/string.rb', line 11 def to_snakecase 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 |