joe07734
11/5/2007 11:59:00 AM
Thanks matz and all. The define_method() trick hadn't occurred to me
-- almost the same, indeed. Why couldn't block parameter syntax be
extended to accept optional args: do |x, y=0| ? I Realize that this is
only meaningful for the hypothetical def usage, but come to think of
it I see no reason blocks couldn't accept optional args in cases where
they're .called().
And doesn't calling a proc with [] smell like a cute hack (hey, we've
got this bracket method...) to anyone else?
On Nov 5, 2007, at 12:24 AM, Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: def blah do |x| -- alternate method definition syntax"
> on Mon, 5 Nov 2007 14:07:21 +0900, Joe Holt <joe07734@gmail.com>
> writes:
>
> |Friend wondered why a method definition couldn't be like this:
> |
> |def blah do |x|
> | ...
> |end
>
> This syntax disallows optional arguments. We can't just parse them.
> If you really want to define a method with block parameter style, you
> can do:
>
> define_method(:blah) do |x|
> ...
> end
>
> Almost same, isn't it?
>
> matz.
>