Class: String

Inherits:
Object show all
Defined in:
lib/helpers.rb

Instance Method Summary collapse

Instance Method Details

#camelizeObject



255
256
257
258
259
260
261
# File 'lib/helpers.rb', line 255

def camelize
  if self =~ %r{_}
    split( '_' ).collect( &:capitalize ).join( '' )
  else
    capitalize
  end
end

#classifyObject



263
264
265
266
267
268
269
# File 'lib/helpers.rb', line 263

def classify
  if self =~ %r{/}
    split( '/' ).collect( &:camelize ).join( '::' )
  else
    camelize
  end
end

#constantizeObject



271
272
273
# File 'lib/helpers.rb', line 271

def constantize
  eval( classify )
end

#humanizeObject



279
280
281
# File 'lib/helpers.rb', line 279

def humanize
  split( '_' ).collect( &:capitalize ).join( ' ' )
end

#pluralizeObject

poor man’s…



284
285
286
# File 'lib/helpers.rb', line 284

def pluralize
  "#{self}s"
end

#underscoreObject



275
276
277
# File 'lib/helpers.rb', line 275

def underscore
  gsub(/([a-zA-Z])([A-Z])/, '\1_\2').downcase
end