Sha256: 52e18166463f9eceb24cb2c73513a204ccfd98a716c01885caa37175786dac24

Contents?: true

Size: 467 Bytes

Versions: 3

Compression:

Stored size: 467 Bytes

Contents

class Hash
  # { foo: :bar }.to_hwia            #
  # { foo: :bar }.to_hwia :foo, :bar # create struct and fill
  def to_hwia *args
    unless args.first
      HashWia.new self
    else
      list = args.flatten
      name = 'DynStruct_' + list.join('_')
      HashWia::STRUCTS[name] ||= ::Struct.new(name, *list)

      HashWia::STRUCTS[name].new.tap do |o|
        each do |k, v|
          o.send('%s=' % k, v) unless v.nil?
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hash_wia-0.7.2 ./lib/hash_wia/pollute.rb
hash_wia-0.7.1 ./lib/hash_wia/pollute.rb
hash_wia-0.7.0 ./lib/hash_wia/pollute.rb