Class: String

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

Overview

Underscore and camelize method … DarBackup.underscore => dar_backup.camelize => DarBackup stolen from rails code ;) api.rubyonrails.org/classes/ActiveSupport/Inflector.html Rails is released under the MIT licens as you can see at rubyonrails.org/

Instance Method Summary collapse

Instance Method Details

#camelizeObject



39
40
41
42
# File 'lib/gat/extends.rb', line 39

def camelize
  self.gsub(/\/(.?)/) { "::#{ $1.upcase }" }.
       gsub(/(?:^|_)(.)/) { $1.upcase }
end

#underscoreObject



30
31
32
33
34
35
36
# File 'lib/gat/extends.rb', line 30

def underscore
  self.gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  downcase
end