private TopSelfFactory() {
super();
}
public static IRubyObject createTopSelf(final Ruby runtime) {
IRubyObject topSelf = new RubyObject(runtime, runtime.getObject());
topSelf.getSingletonClass().defineFastMethod("to_s", new Callback() {
/**
* @see org.jruby.runtime.callback.Callback#execute(IRubyObject, IRubyObject[])
*/
public IRubyObject execute(IRubyObject recv, IRubyObject[] args, Block block) {
return runtime.newString("main");
}
/**
* @see org.jruby.runtime.callback.Callback#getArity()
*/
public Arity getArity() {
return Arity.noArguments();
}
});
// The following three methods must be defined fast, since they expect to modify the current frame
// (i.e. they expect no frame will be allocated for them). JRUBY-1185.
topSelf.getSingletonClass().defineFastPrivateMethod("include", new Callback() {
/**
* @see org.jruby.runtime.callback.Callback#execute(IRubyObject, IRubyObject[])
*/
public IRubyObject execute(IRubyObject recv, IRubyObject[] args, Block block) {
runtime.secure(4);
return runtime.getObject().include(args);
}
/**
* @see org.jruby.runtime.callback.Callback#getArity()
*/
public Arity getArity() {
return Arity.optional();
}
});
topSelf.getSingletonClass().defineFastPrivateMethod("public", new Callback() {
/**
* @see org.jruby.runtime.callback.Callback#execute(IRubyObject, IRubyObject[])
*/
public IRubyObject execute(IRubyObject recv, IRubyObject[] args, Block unusedBlock) {
return runtime.getObject().rbPublic(recv.getRuntime().getCurrentContext(), args);
}
/**
* @see org.jruby.runtime.callback.Callback#getArity()
*/
public Arity getArity() {
return Arity.optional();
}
});
topSelf.getSingletonClass().defineFastPrivateMethod("private", new Callback() {
/**
* @see org.jruby.runtime.callback.Callback#execute(IRubyObject, IRubyObject[])
*/
public IRubyObject execute(IRubyObject recv, IRubyObject[] args, Block unusedBlock) {
return runtime.getObject().rbPrivate(recv.getRuntime().getCurrentContext(), args);