Module: Injectable::Inflector

Defined in:
lib/injectable/inflector.rb

Overview

Used so we don’t need active support around to perform inflections.

Since:

  • 0.0.4

Class Method Summary collapse

Class Method Details

.underscore(string) ⇒ String

Underscore a string. This is partially taken from Active Support, but dumbed down for our purposes - we don’t handle namespacing.

Examples:

Underscore a string.

Inflector.underscore("Band")

Parameters:

  • string (String)

    The string to underscore.

Returns:

  • (String)

    The underscored string.

Since:

  • 0.0.4



22
23
24
25
26
27
# File 'lib/injectable/inflector.rb', line 22

def underscore(string)
  value = string.dup
  value.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
  value.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
  value.downcase!
end