From: James Edward Gray II Date: 2006-01-09T23:05:32+09:00 Subject: Re: hash as paramerter container On Jan 9, 2006, at 7:53 AM, 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 Here are some ideas: >> def show( a, b, c) >> puts "a is #{a}" >> puts "b is #{b}" >> puts "c is #{c}" >> end => nil >> params = {:a => 1, :b => 2, :c => 3} => {:b=>2, :c=>3, :a=>1} >> show(*params.values_at(:a, :b, :c)) a is 1 b is 2 c is 3 => nil That's about the closet I can get what what you posted, I think. >> def show( args ) >> [:a, :b, :b].each { |key| puts "#{key} is #{args[key]}" } >> end => nil >> show(:a => 1, :b => 2, :c => 3) a is 1 b is 2 b is 2 => [:a, :b, :b] This one is more Rubyish though, to me. It uses Ruby's almost named parameter syntax. Hope that gives you some new ideas. James Edward Gray II