Class: Mapping

Inherits:
Object
  • Object
show all
Defined in:
lib/universum/universum.rb

Class Method Summary collapse

Class Method Details

.of(*args) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/universum/universum.rb', line 82

def self.of( *args )
   ## e.g. gets passed in [{Address=>Integer}]
   ##  check for Integer - use Hash.new(0)
   ##  check for Bool    - use Hash.new(False)
   if args[0].is_a? Hash
     arg = args[0].to_a   ## convert to array (for easier access)
     if arg[0][1] == Integer
       Hash.new( Integer.zero )     ## if key missing returns 0 and NOT nil (the default)
     elsif arg[0][1] == Money
       Hash.new( Money.zero )     ## if key missing returns 0 and NOT nil (the default)
     elsif arg[0][1] == Bool
       Hash.new( Bool.zero )
     elsif arg[0][1] == Address
       Hash.new( Address.zero )
     else   ## assume "standard" defaults
       ## todo: issue warning about unknown type - why? why not?
       Hash.new
     end
   else
     Hash.new    ## that is, "plain" {} with all "standard" defaults
   end
end