Subtle C# vs Ruby Inheritence Difference August 17, 2009
This subtle differences in ruby and C#'s inheritence semantics bit me in the ass.
Calling "B.new.foo" will output "in b". I assumed this is how method overriding worked in C#, but that was a mistake. The same example in C# would output "in a", because the `bar` referenced in A is not a message (like it is in ruby,) the compiler just sticks in the reference to the locally defined function. An hour, a fistful of hair, and a call to a good friend (thanks AJ) later, I came to realize that in order to get the same kind of behavior, you have to use the "virtual" and "override" keywords in your classes' method signatures.
In Ruby:
class A def foo bar end def bar "in a" end end class B < A def bar "in b" end end
This is a great article that explains it all: C# Overriding (virtual, override)