Robert Dober wrote:
> On Nov 3, 2007 1:27 AM, Trans <transfire / gmail.com> wrote:
>> Lets say I have a method using the not-so-uncommon keyword options
>> pattern:
>>
>>   def foo(*args)
>>     opts  = (Hash === args.last ? args.pop : {})
> 
> Hi Tom
> 
> irb(main):001:0> def foo *args
> irb(main):002:1>   opts, args = args.partition{|x| Hash === x }
> irb(main):003:1>   opts = opts.inject{ |s,x| s.update x }
> 
> seems this should do the trick
>>     ...

Why not simply:

def foo(*args)
  opts = args[0]
  args = args[1..-1]

  p opts, args
end

def bar(opt, *args)
  foo(:baz =>opt, *args)
  puts
  foo(:baz =>opt, :other => 'pie', *args)
end

bar(10, 20, 30)


--output:--
{:baz=>10}
[20, 30]

{:baz=>10, :other=>"pie"}
[20, 30]

-- 
Posted via http://www.ruby-forum.com/.