Robert Klemme
2/4/2006 12:39:00 PM
csn <cool_screen_name90001@yahoo.com> wrote:
> Is there a Ruby function similar to PHP's extract/list? What I'd like
> to do is:
>
> def foo(args={a=>1, b=>2, c=>3})
> args.extract
>
> puts a
> puts b
> puts c
> end
>
> Thanks
> csn
You cannot do that as local variables have to be declared in the code.
You'll have to do that by hand, i.e.,
def foo(args={:a=>1, :b=>2, :c=>3})
a = args[:a] || 1
b = args[:b] || 2
a = args[:c] || 3
puts a,b,c
end
or
def foo(args={})
args = args.merge(:a=>1, :b=>2, :c=>3)
a = args[:a]
b = args[:b]
a = args[:c]
puts a,b,c
end
What do you need that for? Maybe there is a better solution.
Kind regards
robert