Sha256: 930e1095180a5c3e04fdaf2f52e92b81b44e7403a25eff262664d0ce6eeafd35

Contents?: true

Size: 510 Bytes

Versions: 4

Compression:

Stored size: 510 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
      extra = keys - list

      if extra.first
        raise ArgumentError.new('Unallowed key/s: %s' % extra.map{ |_| ':%s' % _ }.join(', '))
      end

      HashWia.new.tap do |o|
        list.each do |k|
          o[k] = self[k]
        end

        o.freeze_keys!
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hash_wia-0.8.0 ./lib/hash_wia/pollute.rb
hash_wia-0.7.12 ./lib/hash_wia/pollute.rb
hash_wia-0.7.11 ./lib/hash_wia/pollute.rb
hash_wia-0.7.10 ./lib/hash_wia/pollute.rb