Sha256: fa69bf67bf46df62c5e8a099a7e8c48fa183eecb3037214b27701d93b4320f3e

Contents?: true

Size: 617 Bytes

Versions: 2

Compression:

Stored size: 617 Bytes

Contents

require 'hashie/mash'

module Hashie
  class Rash < Mash

    protected

      def convert_key(key) #:nodoc:
        underscore_string(key.to_s)
      end

      # converts a camel_cased string to a underscore string
      # subs spaces with underscores, strips whitespace
      # Same way ActiveSupport does string.underscore
      def underscore_string(str)
        str.to_s.strip.
          gsub(' ', '_').
          gsub(/::/, '/').
          gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
          gsub(/([a-z\d])([A-Z])/,'\1_\2').
          tr("-", "_").
          squeeze("_").
          downcase
      end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rash-0.3.2 lib/hashie/rash.rb
rash-0.3.1 lib/hashie/rash.rb