Sha256: 29b2d422e22045ae8a77c629e97af7d6d0d83ff0cd43176162dfc046b36a1406

Contents?: true

Size: 583 Bytes

Versions: 3

Compression:

Stored size: 583 Bytes

Contents

module SinatraResource

  module Utility

    # The reverse of +camelize+. Makes an underscored, lowercase form from
    # the expression in the string.
    #
    # @param [String] camel_cased_word
    #
    # @return [String]
    #
    # Example:
    #   "SourceGroup".underscore # => "source_group"
    #
    # (This method was adapted from ActiveSupport 2.3.5)
    def self.underscore(camel_cased_word)
      camel_cased_word.to_s.
        gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
        gsub(/([a-z\d])([A-Z])/, '\1_\2').
        tr("-", "_").
        downcase
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sinatra_resource-0.4.24 lib/utility.rb
sinatra_resource-0.4.23 lib/utility.rb
sinatra_resource-0.4.22 lib/utility.rb