Module: Hadley::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/hadley/utils.rb

Overview

This module contains a collection of generally useful methods that (currently) have no better place to live. They can either be referenced directly as module methods or be mixed in.

Instance Method Summary collapse

Instance Method Details

#camelize(name, uc_first = true) ⇒ String

This method will derive a camelized name from the provided underscored name.

Parameters:

  • name (#to_s)

    The underscored name to be camelized.

  • uc_first (Boolean) (defaults to: true)

    True if and only if the first letter of the resulting camelized name should be capitalized.

Returns:

  • (String)

    The camelized name corresponding to the provided underscored name.



13
14
15
16
17
# File 'lib/hadley/utils.rb', line 13

def camelize(name, uc_first=true)
  parts = name.to_s.split('_')
  assemble = lambda { |head, tail| head + tail.capitalize }
  uc_first ? parts.inject('', &assemble) : parts.inject(&assemble)
end