From: Adam Shelly Date: 2006-01-10T02:37:39+09:00 Subject: Re: hash as paramerter container What about irb(main):033:0> h = {:c=>333,:b=>2, :a=>1} => {:c=>333, :a=>1, :b=>2} irb(main):034:0> def foo h irb(main):035:1> puts "a is #{h[:a]}" irb(main):036:1> puts "b is #{h[:b]}" irb(main):037:1> puts "c is #{h[:c]}" irb(main):038:1> end => nil irb(main):039:0> foo h a is 1 b is 2 c is 333 => nil > Sch�le Daniel wrote: > > Hello all, > > > > I am looking for Ruby equivalent for this Python Code > > > > >>> def foo(a,b,c): > > ... print "a is ", a > > ... print "b is ", b > > ... print "c is ", c > > ... > > >>> h = {"c":3, "a":1, "b":2} > > >>> > > >>> foo > > > > >>> foo(**h) > > a is 1 > > b is 2 > > c is 3 > > > > my first try > > > > => {"c"=>333, :b=>2, :a=>1} > > irb(main):017:0> def foo a,b,c > > irb(main):018:1> puts "a is #{a}" > > irb(main):019:1> puts "b is #{b}" > > irb(main):020:1> puts "c is #{c}" > > irb(main):021:1> end > > => nil > > irb(main):022:0> foo *h > > a is c333 > > b is b2 > > c is a1 > > => nil > > > > > > this seem to replace (or substituate) the parameters expected by foo > > in the order of hash. And since hash has no order (in both languages) > > it's a random replacement. > > > > Is there a trick I don't know about?