/** * Removes this object from {@link BiVariableMap}. * * @param runtime environment where a variable is removed. */ @Override public void remove() { synchronized (receiver.getRuntime()) { String varname = (name.startsWith("$") ? name : "$" + name); receiver.getRuntime().getGlobalVariables().clear(varname.intern()); } } }
/** * Removes this object from {@link BiVariableMap}. * * @param runtime environment where a variable is removed. */ @Override public void remove() { synchronized (getRuntime()) { String gName = (name.startsWith("$") ? name : "$" + name); getRuntime().getGlobalVariables().clear( gName.intern() ); } } }
/** * Removes this object from {@link BiVariableMap}. * * @param runtime environment where a variable is removed. */ @Override public void remove() { synchronized (getRuntime()) { String gName = (name.startsWith("$") ? name : "$" + name); getRuntime().getGlobalVariables().clear( gName.intern() ); } } }
/** * Attempts to remove this variable from top self or receiver. * */ @Override public void remove() { synchronized (getRuntime()) { getRuntime().getGlobalVariables().clear(name.intern()); } }
/** * Removes this object from {@link BiVariableMap}. * * @param runtime environment where a variable is removed. */ @Override public void remove() { synchronized (receiver.getRuntime()) { String varname = (name.startsWith("$") ? name : "$" + name); receiver.getRuntime().getGlobalVariables().clear(varname.intern()); } } }
/** * Attempts to remove this variable from top self or receiver. * */ @Override public void remove() { synchronized (getRuntime()) { getRuntime().getGlobalVariables().clear(name.intern()); } }
/** * Attempts to remove this variable from top self or receiver. * */ public void remove() { synchronized (receiver.getRuntime()) { receiver.getRuntime().getGlobalVariables().clear(name.intern()); } }
/** * Attempts to remove this variable from top self or receiver. * */ public void remove() { synchronized (receiver.getRuntime()) { receiver.getRuntime().getGlobalVariables().clear(name.intern()); } }
@JRubyMethod(required = 1, rest = true, meta = true) public static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { Ruby runtime = context.runtime; RubyClass klass = (RubyClass)recv; RubyIO io = (RubyIO)klass.newInstance(context, args, block); if (block.isGiven()) { try { return block.yield(context, io); } finally { try { io.getMetaClass().finvoke(context, io, "close", IRubyObject.NULL_ARRAY, Block.NULL_BLOCK); } catch (RaiseException re) { RubyException rubyEx = re.getException(); if (rubyEx.kind_of_p(context, runtime.getStandardError()).isTrue()) { // MRI behavior: swallow StandardErorrs runtime.getGlobalVariables().clear("$!"); } else { throw re; } } } } return io; }
@JRubyMethod(required = 1, rest = true, meta = true) public static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { Ruby runtime = context.runtime; RubyClass klass = (RubyClass)recv; RubyIO io = (RubyIO)klass.newInstance(context, args, block); if (block.isGiven()) { try { return block.yield(context, io); } finally { try { io.getMetaClass().finvoke(context, io, "close", IRubyObject.NULL_ARRAY, Block.NULL_BLOCK); } catch (RaiseException re) { RubyException rubyEx = re.getException(); if (rubyEx.kind_of_p(context, runtime.getStandardError()).isTrue()) { // MRI behavior: swallow StandardErorrs runtime.getGlobalVariables().clear("$!"); } else { throw re; } } } } return io; }
private static IRubyObject foreachInternal(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { Ruby runtime = context.runtime; IRubyObject opt = ArgsUtil.getOptionsArg(context.runtime, args); RubyIO io = openKeyArgs(context, recv, args, opt); if (io == context.nil) return io; // replace arg with coerced opts if (opt != context.nil) args[args.length - 1] = opt; // io_s_foreach, roughly try { switch (args.length) { case 1: Getline.getlineCall(context, GETLINE_YIELD, io, io.getReadEncoding(context), block); break; case 2: Getline.getlineCall(context, GETLINE_YIELD, io, io.getReadEncoding(context), args[1], block); break; case 3: Getline.getlineCall(context, GETLINE_YIELD, io, io.getReadEncoding(context), args[1], args[2], block); break; case 4: Getline.getlineCall(context, GETLINE_YIELD, io, io.getReadEncoding(context), args[1], args[2], args[3], block); break; } } finally { io.close(); context.setLastLine(context.nil); runtime.getGlobalVariables().clear("$_"); } return context.nil; }
private static IRubyObject foreachInternal(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { Ruby runtime = context.runtime; IRubyObject opt = ArgsUtil.getOptionsArg(context.runtime, args); RubyIO io = openKeyArgs(context, recv, args, opt); if (io == context.nil) return io; // replace arg with coerced opts if (opt != context.nil) args[args.length - 1] = opt; // io_s_foreach, roughly try { switch (args.length) { case 1: Getline.getlineCall(context, GETLINE_YIELD, io, io.getReadEncoding(context), block); break; case 2: Getline.getlineCall(context, GETLINE_YIELD, io, io.getReadEncoding(context), args[1], block); break; case 3: Getline.getlineCall(context, GETLINE_YIELD, io, io.getReadEncoding(context), args[1], args[2], block); break; case 4: Getline.getlineCall(context, GETLINE_YIELD, io, io.getReadEncoding(context), args[1], args[2], args[3], block); break; } } finally { io.close(); context.setLastLine(context.nil); runtime.getGlobalVariables().clear("$_"); } return context.nil; }
/** rb_io_s_foreach * */ private static IRubyObject foreachInternal19(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { Ruby runtime = context.runtime; IRubyObject opt = ArgsUtil.getOptionsArg(context.runtime, args); IRubyObject io = openKeyArgs(context, recv, args, opt); if (io.isNil()) return io; IRubyObject[] methodArguments = processReadlinesMethodArguments(args); ByteListCache cache = new ByteListCache(); if (!io.isNil()) { try { long limit = ((RubyIO)io).getLimitFromArgs(methodArguments); ByteList separator = ((RubyIO)io).getSeparatorFromArgs(runtime, methodArguments, 0); IRubyObject str = ((RubyIO)io).getline(context, separator, limit ,cache); while (!str.isNil()) { block.yield(context, str); str = ((RubyIO)io).getline(context, separator, limit ,cache); } } finally { ((RubyIO)io).close(); runtime.getGlobalVariables().clear("$_"); } } return runtime.getNil(); }
/** rb_io_s_foreach * */ private static IRubyObject foreachInternal19(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { Ruby runtime = context.runtime; IRubyObject opt = ArgsUtil.getOptionsArg(context.runtime, args); IRubyObject io = openKeyArgs(context, recv, args, opt); if (io.isNil()) return io; IRubyObject[] methodArguments = processReadlinesMethodArguments(args); ByteListCache cache = new ByteListCache(); if (!io.isNil()) { try { long limit = ((RubyIO)io).getLimitFromArgs(methodArguments); ByteList separator = ((RubyIO)io).getSeparatorFromArgs(runtime, methodArguments, 0); IRubyObject str = ((RubyIO)io).getline(context, separator, limit ,cache); while (!str.isNil()) { block.yield(context, str); str = ((RubyIO)io).getline(context, separator, limit ,cache); } } finally { ((RubyIO)io).close(); runtime.getGlobalVariables().clear("$_"); } } return runtime.getNil(); }