Logo Search packages:      
Sourcecode: jruby1.1 version File versions

IRubyObject org::jruby::RubyObject::extend ( IRubyObject[]  args  )  [inline, inherited]


call-seq: obj.extend(module, ...) => obj

Adds to _obj_ the instance methods from each module given as a parameter.

module Mod def hello "Hello from Mod.\n" end end

class Klass def hello "Hello from Klass.\n" end end

k = Klass.new k.hello #=> "Hello from Klass.\n" k.extend(Mod) #=> #<Klass:0x401b3bc8> k.hello #=> "Hello from Mod.\n"

Definition at line 1986 of file RubyObject.java.

References org::jruby::Ruby::getCurrentContext(), org::jruby::Ruby::getModule(), and org::jruby::Ruby::newTypeError().

        Ruby runtime = getRuntime();
        // Make sure all arguments are modules before calling the callbacks
        for (int i = 0; i < args.length; i++) {
            if (!args[i].isModule()) throw runtime.newTypeError(args[i], runtime.getModule()); 

        ThreadContext context = runtime.getCurrentContext();
        // MRI extends in order from last to first
        for (int i = args.length - 1; i >= 0; i--) {
            args[i].callMethod(context, "extend_object", this);
            args[i].callMethod(context, "extended", this);
        return this;

Generated by  Doxygen 1.6.0   Back to index