mhm26
11/20/2003 1:18:00 AM
matz@ruby-lang.org (Yukihiro Matsumoto) wrote in message news:<1069269880.596357.859.nullmailer@picachu.netlab.jp>...
> Hi,
>
> In message "break in yield/block"
> on 03/11/20, matt <mhm26@drexel.edu> writes:
>
> |Is there any reason that break acts differently in a block passed to a
> |method depending on whether yield is used?
>
> Because they are different. "break" in a block terminates a method
> that the block is attached to. In your example, it is "meow" when
> doyield, and "[]" when not.
>
> I'm not sure what you think they should be.
>
> matz.
I figured that was why break was terminating in #[] - but why not have
yield act as a `method' in this sense? My guess is that in this
respect, they should be the same. Should I really be writing my
blocks to work a certain way depending on whether the implementor
decided to use yield or [], or whether I'm doing something like
list_of_methods_args.each {|meth, *args| meth.call(args,
&special_magic)}
(this is assuming that there are stand alone methods attached to
instances - I heard there are in 1.8.x - otherwise, rework code yadda
yadda)
- then I have to worry about how blocks are used in each one if
special_magic uses break - what if the list was made dynamically from
reflection, etc? Granted, I generally don't use break - especially in
lambdas - but its still something I didn't expect.
~Me!