Discussions On Block Local Variable And Method Search Rule Of Ruby2 #
Sasada tai-tyou has collected Matz’s suggestions of Ruby21 from his blog and created Wiki entries. Discussions are continued on the ruby-dev mailing list.
References:
- Ruby2.0spec [ja]
- Rite [en]
1 Ruby2 is the language specification. Rite is an implementation.
eero
Good stuff! The Ruby2.0spec is in both English and Japanese, by the way.
kHebSkik
With the proposed method search, overriding methods in extending classes will become impossible. Code like this will not be possible anymore:
Unless I completely misunderstood, that is…
joesb
I understand that this is like ‘virtual’ keyword for C++ methods, except that it’s determine at call site, instead of dclaration site.
In your example, if you call a method faa using
, then new faa definition will be used.But if your foo call faa as simply “faa” then, the new definition will not be used.
So this kinda makes the original writer of caller have to decide in advance whether they’ll ever want to allow new definition to be used in case of this one function call. If they want to allow it, they will use self.faa form.
Jim Weirich
It’s a bit unclear. The discussion starts out about private methods, but the follow-on examples never mention private.
If the proposed new search order is for private methods only, then it seems reasonable.
If the proposed new search order is for all methods, then it makes things like the GOF Template Method Pattern impossible (well, at least difficult) to implement in Ruby.
kHebSkik
Ah private methods. I already thought I missed something.
Daniel Berger
Jim, I hope very much you are correct.
Umboy
Yes, because this would awful if applied in general. Bad, bad, bad idea. Talk about violating POLS !
Steven Lumos
Can somebody please translate the part of BlockLocalVariable near:
Because yipes...
daigo
Block parameters that are defined as local variables out of the block’s scope are not available.
Comments are closed for this entry.