1 31 package org.jruby; 32 33 import org.jruby.runtime.Arity; 34 import org.jruby.runtime.Block; 35 import org.jruby.runtime.builtin.IRubyObject; 36 import org.jruby.runtime.callback.Callback; 37 38 42 public final class TopSelfFactory { 43 44 47 private TopSelfFactory() { 48 super(); 49 } 50 51 public static IRubyObject createTopSelf(final Ruby runtime) { 52 IRubyObject topSelf = new RubyObject(runtime, runtime.getObject()); 53 54 topSelf.defineSingletonMethod("to_s", new Callback() { 55 58 public IRubyObject execute(IRubyObject recv, IRubyObject[] args, Block block) { 59 return runtime.newString("main"); 60 } 61 62 65 public Arity getArity() { 66 return Arity.noArguments(); 67 } 68 }); 69 70 topSelf.defineSingletonMethod("include", new Callback() { 71 74 public IRubyObject execute(IRubyObject recv, IRubyObject[] args, Block block) { 75 runtime.secure(4); 76 return runtime.getObject().include(args); 77 } 78 79 82 public Arity getArity() { 83 return Arity.optional(); 84 } 85 }); 86 87 topSelf.defineSingletonMethod("public", new Callback() { 88 91 public IRubyObject execute(IRubyObject recv, IRubyObject[] args, Block unusedBlock) { 92 return runtime.getObject().rbPublic(args); 93 } 94 95 98 public Arity getArity() { 99 return Arity.optional(); 100 } 101 }); 102 103 topSelf.defineSingletonMethod("private", new Callback() { 104 107 public IRubyObject execute(IRubyObject recv, IRubyObject[] args, Block unusedBlock) { 108 return runtime.getObject().rbPrivate(args); 109 } 110 111 114 public Arity getArity() { 115 return Arity.optional(); 116 } 117 }); 118 119 return topSelf; 120 } 121 } 122 | Popular Tags |