Class: String

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

Instance Method Summary collapse

Instance Method Details

#camelizeObject



87
88
89
90
# File 'lib/waffle.rb', line 87

def camelize
  string = sub(/^[a-z\d]*/){$&.capitalize}
  string.gsub(/(?:_|(\/))([a-z\d]*)/){ "#{$1}#{$2.capitalize}" }.gsub('/', '::')
end

#constantizeObject



76
77
78
79
80
81
82
83
84
85
# File 'lib/waffle.rb', line 76

def constantize
  names = self.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