On Sun, Jan 9, 2011 at 7:14 PM, Yukihiro Matsumoto <matz / ruby-lang.org> wrote:
> |Are you thinking of a method is defined in C that uses Data_Wrap_Struct ?
>
> No, I am thinking of methods defined for modules, that have no
> assumption of the type of receivers. Ruby methods in C does not check
> the type of the receiver, so that if you move a method from String
> class to, say, Array, the interpreter will crash when you call the
> transplanted method.

The same applies in JRuby for a slightly different reason: methods on
core classes are usually defined as instance methods on Java-based
classes like RubyArray or RubyString. Transplanting them to another
class would, for example, attempt to call a RubyArray method against a
RubyString instance, and throw a Java ClassCastExeption.
Essentially...it would crash :)

This is also the reason JRuby does not change the class of the IO
object when doing reopen; the concrete Java type is set at
construction time, and can't be changed (e.g. a file is RubyFile, and
always will be).

- Charlie