[Ironruby-core] Sealed method can be overriden

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


That's expected. If you change "sealed override" to just "override" the method is virtual and Ruby subclasses will override it.
In both cases NewSquare.new.GetNumberOfSizes finds CLR method Square::GetNumberOfSizes and invokes it. In the first case, the method is not overridden and therefore the implementation in Square gets executed. Without "sealed" the method is overridden by NewSquare#get_number_of_sizes and therefore the virtual dispatch executes NewSquare's implementation. 

In both cases NewSquare.new.get_number_of_sizes finds Ruby method NewSquare#get_number_of_sizes and executes it.

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:03 PM
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] Sealed method can be overriden

There is a slight difference though.
In the example:
puts NewSquare.new.get_number_of_sizes # => 99
puts NewSquare.new.GetNumberOfSizes # => 4


If I change the example to a regular method (not sealed), the output is 
slightly different:
puts NewSquare.new.get_number_of_sizes # => 99
puts NewSquare.new.GetNumberOfSizes # => 99

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