[Ironruby-core] Sealed method can be overriden

Tomas Matousek Tomas.Matousek at microsoft.com
Sat Jun 13 15:49:22 EDT 2009


C#:
public class C {
  public int FooBar() { return 123; }
}

Ruby:
require 'x.dll'

class D < C
  def foo_bar 
    48
  end
end

p D.new.FooBar            # => 123
p D.new.foo_bar           # => 48

The same rules hold here: foo_bar does NOT override FooBar (since FooBar is not virtual) and therefore is an unrelated method.
So the first call resolves to C::FooBar and invokes it.
The second call resolves to D#foo_bar and invokes it. Only if there wasn't foo_bar or FooBar defined in D this call would resolve to C::FooBar.

Tomas

-----Original Message-----
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shay Friedman
Sent: Saturday, June 13, 2009 12:36 PM
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] Sealed method can be overriden

The same happens with non-virtual methods as well.

By the way, should you be able to call super when you override a virtual 
method?

Thanks,
Shay.

----------------------------
Shay Friedman
http://www.ironshay.com
Follow me: http://twitter.com/ironshay
-- 
Posted via http://www.ruby-forum.com/.
_______________________________________________
Ironruby-core mailing list
Ironruby-core at rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core



More information about the Ironruby-core mailing list