Sha256: 2889107774cef01284d9e0d15763c4745dcf19f58027a80c84be48f508dac411

Contents?: true

Size: 342 Bytes

Versions: 20

Compression:

Stored size: 342 Bytes

Contents

class Hash

  # A method to convert a Hash into a Struct.
  #
  #   h = {:name=>"Dan","age"=>33,"rank"=>"SrA","grade"=>"E4"}
  #   s = h.to_struct("Foo")
  #
  # TODO: Is this robust enough considerd hashes aren't ordered?
  #
  # CREDIT: Daniel Berger

  def to_struct(struct_name)
    Struct.new(struct_name,*keys).new(*values)
  end

end

Version data entries

20 entries across 19 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/hash/to_struct.rb
facets-3.1.0 lib/core/facets/hash/to_struct.rb
facets-3.0.0 lib/core/facets/hash/to_struct.rb
facets-2.9.3 lib/core/facets/hash/to_struct.rb
facets-2.9.2 lib/core/facets/hash/to_struct.rb
facets-2.9.2 src/core/facets/hash/to_struct.rb
facets-2.9.1 lib/core/facets/hash/to_struct.rb
facets-2.9.0 lib/core/facets/hash/to_struct.rb
facets-2.9.0.pre.2 lib/core/facets/hash/to_struct.rb
facets-2.9.0.pre.1 lib/core/facets/hash/to_struct.rb
facets-2.8.4 lib/core/facets/hash/to_struct.rb
facets-2.8.3 lib/core/facets/hash/to_struct.rb
facets-2.8.2 lib/core/facets/hash/to_struct.rb
facets-2.8.1 lib/core/facets/hash/to_struct.rb
facets-2.8.0 lib/core/facets/hash/to_struct.rb
facets-2.7.0 lib/core/facets/hash/to_struct.rb
facets-2.6.0 lib/core/facets/hash/to_struct.rb
facets-2.5.0 lib/core/facets/hash/to_struct.rb
facets-2.5.1 lib/core/facets/hash/to_struct.rb
facets-2.5.2 lib/core/facets/hash/to_struct.rb