@JRubyMethod(name = "define_method", visibility = PRIVATE, reads = VISIBILITY) public IRubyObject define_method(ThreadContext context, IRubyObject arg0, Block block) { Ruby runtime = context.runtime; String name = TypeConverter.convertToIdentifier(arg0); DynamicMethod newMethod = null; Visibility visibility = PUBLIC; // We need our identifier to be retrievable and creatable as a symbol. This side-effect // populates this name into our symbol table so it will exist later if needed. The // reason for this hack/side-effect is that symbols store their values as raw bytes. We lose encoding // info so we need to make an entry so any accesses with raw bytes later gets proper symbol. RubySymbol.newSymbol(runtime, arg0); if (!block.isGiven()) { throw getRuntime().newArgumentError("tried to create Proc object without a block"); } block = block.cloneBlockAndFrame(); RubyProc proc = runtime.newProc(Block.Type.LAMBDA, block); // a normal block passed to define_method changes to do arity checking; make it a lambda proc.getBlock().type = Block.Type.LAMBDA; newMethod = createProcMethod(name, visibility, proc); Helpers.addInstanceMethod(this, name, newMethod, visibility, context, runtime); return proc; }
@JRubyMethod(name = "define_method", visibility = PRIVATE, reads = VISIBILITY) public IRubyObject define_method(ThreadContext context, IRubyObject arg0, Block block) { Ruby runtime = context.runtime; String name = TypeConverter.convertToIdentifier(arg0); DynamicMethod newMethod = null; Visibility visibility = PUBLIC; // We need our identifier to be retrievable and creatable as a symbol. This side-effect // populates this name into our symbol table so it will exist later if needed. The // reason for this hack/side-effect is that symbols store their values as raw bytes. We lose encoding // info so we need to make an entry so any accesses with raw bytes later gets proper symbol. RubySymbol.newSymbol(runtime, arg0); if (!block.isGiven()) { throw getRuntime().newArgumentError("tried to create Proc object without a block"); } block = block.cloneBlockAndFrame(); RubyProc proc = runtime.newProc(Block.Type.LAMBDA, block); // a normal block passed to define_method changes to do arity checking; make it a lambda proc.getBlock().type = Block.Type.LAMBDA; newMethod = createProcMethod(name, visibility, proc); Helpers.addInstanceMethod(this, name, newMethod, visibility, context, runtime); return proc; }
Ruby runtime = context.runtime; IRubyObject body; String name = TypeConverter.convertToIdentifier(arg0); DynamicMethod newMethod = null; Visibility visibility = PUBLIC;
Ruby runtime = context.runtime; IRubyObject body; String name = TypeConverter.convertToIdentifier(arg0); DynamicMethod newMethod = null; Visibility visibility = PUBLIC;