Sha256: d341532ad03f1a17cf21058053bc457992bc48e9bcc997038d22f9b82912bbf4

Contents?: true

Size: 581 Bytes

Versions: 7

Compression:

Stored size: 581 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

7 entries across 7 versions & 1 rubygems

Version Path
sinatra_resource-0.4.21 lib/utility.rb
sinatra_resource-0.4.20 lib/utility.rb
sinatra_resource-0.4.19 lib/utility.rb
sinatra_resource-0.4.18 lib/utility.rb
sinatra_resource-0.4.17 lib/utility.rb
sinatra_resource-0.4.16 lib/utility.rb
sinatra_resource-0.4.15 lib/utility.rb