From: Josh Cheek Date: 2010-05-04T19:14:54+09:00 Subject: Re: * splat error --0016e65426468896690485c1fad4 Content-Type: text/plain; charset=ISO-8859-1 On Tue, May 4, 2010 at 4:31 AM, Ruby Knight wrote: > > > > def s(a,*b,c) end > > ^ > > 11:16:32 test_2$ > > > > Cheers > > > > robert > > > Hi Robert, > > I tried putting end after the last brace but didn't work. I am assuming > there is more to that ^ than just for illustrative purposes. Could you > explain to me why my code is not working? THanks! > > -- > Posted via http://www.ruby-forum.com/. > > Robert is saying that it works in 1.9.1 (see how it says Syntax OK), but not 1.8.7 (where it pulls up the same error you had) For 1.9, you can do something like this def split_apart( first , *splat ) raise ArgumentError.new('wrong number of arguments (1 for 2)') if splat.size.zero? last = splat.pop puts "first: #{first.inspect}, splat: #{splat.inspect}, last: #{last.inspect}" end Though I probably wouldn't bother with the error myself, unless writing code for other people. This is similar to how Rails' find method works, it checks the last argument to see if it is a hash, then if it is, it pops it off (look at their example in the comments) http://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/array/extract_options.rb --0016e65426468896690485c1fad4--