Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/extension.rb

Instance Method Summary collapse

Instance Method Details

#camel_caseObject

returns camel_case representation of string



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/extension.rb', line 8

def camel_case
  if self.include? '_'
    self.split('_').map { |e| e.capitalize }.join
  else
    unless self =~ (/^[A-Z]/)
      self.capitalize
    else
      self
    end
  end
end

#snake_caseObject

returns snake_case representation of string



3
4
5
# File 'lib/extension.rb', line 3

def snake_case
  gsub(/([a-z])([A-Z0-9])/, '\1_\2').downcase
end