Sha256: 4c0c631987dd0308bd88e88092528aa60c60589f5d7b54297373bebc9cf7d33c

Contents?: true

Size: 806 Bytes

Versions: 1

Compression:

Stored size: 806 Bytes

Contents

require 'rubygems'
require 'hashie'

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
    # Same way ActiveSupport does string.underscore
    def underscore_string(str)
      str.to_s.gsub(/::/, '/').
        gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
        gsub(/([a-z\d])([A-Z])/,'\1_\2').
        tr("-", "_").
        downcase
    end
    
    def convert_value(val, duping=false) #:nodoc:
      obj = super
      obj = self.class.new(obj) if Hashie::Mash === obj
      obj
    end
    
    def initializing_reader(key)
      ck = convert_key(key)
      regular_writer(ck, self.class.new) unless key?(ck)
      regular_reader(ck)
    end
    
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rash-0.1.0 lib/rash.rb