hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

Discussions On Block Local Variable And Method Search Rule Of Ruby2 #

by daigo in inspect

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:

1 Ruby2 is the language specification. Rite is an implementation.

said on 04 Apr 2005 at 21:05

Good stuff! The Ruby2.0spec is in both English and Japanese, by the way.

said on 05 Apr 2005 at 06:04

With the proposed method search, overriding methods in extending classes will become impossible. Code like this will not be possible anymore:


 class A # default impl
  def foo
    # stuff that needs
    faa
  end
 end
 class B < A
   # he! I know a better faa
   def faa
     # useless!!
   end
 end
end

Unless I completely misunderstood, that is…

said on 05 Apr 2005 at 06:42

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

self.faa
, 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.

said on 05 Apr 2005 at 06:44

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.

said on 05 Apr 2005 at 07:49

Ah private methods. I already thought I missed something.

said on 05 Apr 2005 at 08:07

Jim, I hope very much you are correct.

said on 05 Apr 2005 at 10:10

Yes, because this would awful if applied in general. Bad, bad, bad idea. Talk about violating POLS !

said on 05 Apr 2005 at 23:36

Can somebody please translate the part of BlockLocalVariable near:


a = 1
iter{|a, b| #=> SyntaxError
   ...
}

Because yipes...

said on 06 Apr 2005 at 00:24

Block parameters that are defined as local variables out of the block’s scope are not available.

Comments are closed for this entry.