~ubuntu-branches/ubuntu/saucy/ruby-facets/saucy

« back to all changes in this revision

Viewing changes to src/core/facets/hash/to_struct.rb

  • Committer: Package Import Robot
  • Author(s): Marc Dequènes (Duck)
  • Date: 2013-06-21 14:41:38 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130621144138-nb3t82yl5gl8p7a6
Tags: 2.9.3-1
* New upstream release:
  - rakefile is gone, switched back to setuprb method
  - recreated documention build rules and adapted to new paths
* Updated copyright file.
* Increased Standards-Version to 3.9.4 (no changes).
* Removed transitional libfacets-* package and obsolete relations.
* Use system JQuery library instead of embedded one for documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
class Hash
2
 
 
3
 
  # A method to convert a Hash into a Struct.
4
 
  #
5
 
  #   h = {:name=>"Dan","age"=>33,"rank"=>"SrA","grade"=>"E4"}
6
 
  #   s = h.to_struct("Foo")
7
 
  #
8
 
  # TODO: Is this robust enough considerd hashes aren't ordered?
9
 
  #
10
 
  # CREDIT: Daniel Berger
11
 
 
12
 
  def to_struct(struct_name)
13
 
    Struct.new(struct_name,*keys).new(*values)
14
 
  end
15
 
 
16
 
end
17