Sha256: 37d86a66d271004ec6c919952ee91cd1e3c0169dfb1474a1bbd1c372da0864dc

Contents?: true

Size: 497 Bytes

Versions: 3

Compression:

Stored size: 497 Bytes

Contents

class Hash
  class Accessible < Indifferent

    private

    def method_missing(method, *args, &block)
      if method.to_s.end_with? '='
        key = method[0..-2]
        self[key] = make_accessible args[0]
      else
        make_accessible self[method]
      end
    end

    def make_accessible(value)
      if value.kind_of? Hash
        self.class.new value
      elsif value.kind_of? Array
        value.map { |v| make_accessible v }
      else
        value
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hash_ext-0.2.0 lib/hash_ext/accessible.rb
hash_ext-0.1.1 lib/hash_ext/accessible.rb
hash_ext-0.1.0 lib/hash_ext/accessible.rb