Class: String

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

Instance Method Summary collapse

Instance Method Details

#camelizeObject



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

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

#classifyObject



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

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

#constantizeObject



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

def constantize
  eval( classify )
end

#humanizeObject



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

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

#pluralizeObject

poor man’s…



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

def pluralize
  "#{self}s"
end

#underscoreObject



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

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