From: Calvin Bornhofen Date: 2012-09-21T01:05:26+09:00 Subject: Re: Splat operator and different options to pass a block Hi, thanks for your answer. I really appreciate it. > First of all, this isn't really a useful technique, because Ruby already > allows you to pass a Proc/Lambda as a block: > > prc = proc {|x| puts x} > [1, 2, 3].each(&prc) Didn't know that was possible, that's really useful. > Secondly, why do you need a separate parameter for the proc argument? > Why not simply pull it out of the args array? > > def test2(foo, *args, &block) > block ||= args.last > block[] > end > > test2('xyz') {puts 1} > test2('xyz', proc {puts 1}) D'oh, didn't think of that. Clearly a much nicer solution. I'm coming from Java, that's why I'm sometimes struggling to find these shortcuts on my own - I'm not fully accustomed to this degree of freedom. ;) Cheers!