Sha256: 721a49793077c53ae06d1d496f4ae1cfe7e6cdfed6b29864cc0c066b75a61faa

Contents?: true

Size: 562 Bytes

Versions: 1

Compression:

Stored size: 562 Bytes

Contents

class HashIsh
  class AddInstanceMethods
    def add(hash_ish, kwargs)
      kwargs.each do |key, value|
        define_method(hash_ish, key, value)
      end
    end

    def define_method(hash_ish, name, value)
      return_value = method_value(value)

      hash_ish.send(:define_singleton_method, name) do
        return_value
      end
    end

    def is_a_hash?(object)
      object.is_a? Hash
    end

    def hash_ish(hash)
      HashIsh.new(hash)
    end

    def method_value(value)
      is_a_hash?(value) ? hash_ish(value) : value
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hash_ish-0.3.0 lib/hash_ish/add_instance_methods.rb