@Override public int size() { return rubyHash.size(); }
@Override public int size() { return rubyHash.size(); }
@SuppressWarnings("unchecked") public String[] getEnv() { RubyHash hash = (RubyHash) runtime.getObject().getConstant("ENV"); String[] env = new String[hash.size()]; if (env.length == 0) return env; StringBuilder str = new StringBuilder(); int i=0; for (Iterator<Entry<Object, Object>> iter = hash.directEntrySet().iterator(); iter.hasNext(); i++) { Map.Entry<Object, Object> entry = iter.next(); str.setLength(0); str.append(entry.getKey()).append('=').append(entry.getValue()); env[i] = str.toString(); } return env; }
@SuppressWarnings("unchecked") public String[] getEnv() { RubyHash hash = (RubyHash) runtime.getObject().getConstant("ENV"); int i=0; String[] env = new String[hash.size()]; for (Iterator<Entry<Object, Object>> iter = hash.directEntrySet().iterator(); iter.hasNext(); i++) { Map.Entry<Object, Object> entry = iter.next(); env[i] = entry.getKey().toString() + "=" + entry.getValue().toString(); } return env; }
@SuppressWarnings("unchecked") public String[] getEnv() { RubyHash hash = (RubyHash) runtime.getObject().getConstant("ENV"); int i=0; String[] env = new String[hash.size()]; for (Iterator<Entry<Object, Object>> iter = hash.directEntrySet().iterator(); iter.hasNext(); i++) { Map.Entry<Object, Object> entry = iter.next(); env[i] = entry.getKey().toString() + "=" + entry.getValue().toString(); } return env; }
@SuppressWarnings("unchecked") public String[] getEnv() { RubyHash hash = (RubyHash) runtime.getObject().getConstant("ENV"); String[] env = new String[hash.size()]; if (env.length == 0) return env; StringBuilder str = new StringBuilder(); int i=0; for (Iterator<Entry<Object, Object>> iter = hash.directEntrySet().iterator(); iter.hasNext(); i++) { Map.Entry<Object, Object> entry = iter.next(); str.setLength(0); str.append(entry.getKey()).append('=').append(entry.getValue()); env[i] = str.toString(); } return env; }
@JRubyMethod(name = "<", required = 1) public IRubyObject op_lt(ThreadContext context, IRubyObject other) { final RubyHash otherHash = ((RubyBasicObject) other).convertToHash(); if (size() >= otherHash.size()) return context.fals; return RubyBoolean.newBoolean(context.runtime, hash_le(otherHash)); }
@JRubyMethod(name = "<", required = 1) public IRubyObject op_lt(ThreadContext context, IRubyObject other) { final RubyHash otherHash = ((RubyBasicObject) other).convertToHash(); if (size() >= otherHash.size()) return context.fals; return RubyBoolean.newBoolean(context.runtime, hash_le(otherHash)); }
@JRubyMethod(name = "hash") public RubyFixnum hash(ThreadContext context) { final int size = size(); long[] hval = { Helpers.hashStart(context.runtime, size) }; if (size > 0) { iteratorVisitAll(context, CalculateHashVisitor, hval); } return context.runtime.newFixnum(hval[0]); }
@JRubyMethod(name = "hash") public RubyFixnum hash(ThreadContext context) { final int size = size(); long[] hval = { Helpers.hashStart(context.runtime, size) }; if (size > 0) { iteratorVisitAll(context, CalculateHashVisitor, hval); } return context.runtime.newFixnum(hval[0]); }
@JRubyMethod(name = "uniq") public IRubyObject uniq19(ThreadContext context, Block block) { if (!block.isGiven()) return uniq(context); RubyHash hash = makeHash(context, block); RubyArray result = new RubyArray(context.runtime, getMetaClass(), hash.size()); hash.visitAll(context, RubyHash.StoreValueVisitor, result); return result; }
private static String mapCharset(ThreadContext context, IRubyObject val) { RubyHash charset = val.getRuntime().getCharsetMap(); if (charset.size() > 0) { RubyString key = val.callMethod(context, "downcase").convertToString(); IRubyObject tryVal = charset.fastARef(key); if (tryVal != null) val = tryVal; } return val.convertToString().toString(); }
@JRubyMethod(name = "uniq") public IRubyObject uniq19(ThreadContext context, Block block) { if (!block.isGiven()) return uniq(context); RubyHash hash = makeHash(context, block); RubyArray result = new RubyArray(context.runtime, getMetaClass(), hash.size()); hash.visitAll(context, RubyHash.StoreValueVisitor, result); return result; }
private static String mapCharset(ThreadContext context, IRubyObject val) { RubyHash charset = val.getRuntime().getCharsetMap(); if (charset.size() > 0) { RubyString key = val.callMethod(context, "downcase").convertToString(); IRubyObject tryVal = charset.fastARef(key); if (tryVal != null) val = tryVal; } return val.convertToString().toString(); }
@JRubyMethod(name = "uniq", compat = RUBY1_9) public IRubyObject uniq19(ThreadContext context, Block block) { if (!block.isGiven()) return uniq(context); RubyHash hash = makeHash(context, block); final RubyArray result = new RubyArray(context.runtime, getMetaClass(), hash.size()); hash.visitAll(new RubyHash.Visitor() { @Override public void visit(IRubyObject key, IRubyObject value) { result.append(value); } }); return result; }
@JRubyMethod(name = "uniq", compat = RUBY1_9) public IRubyObject uniq19(ThreadContext context, Block block) { if (!block.isGiven()) return uniq(context); RubyHash hash = makeHash(context, block); final RubyArray result = new RubyArray(context.runtime, getMetaClass(), hash.size()); hash.visitAll(new RubyHash.Visitor() { @Override public void visit(IRubyObject key, IRubyObject value) { result.append(value); } }); return result; }
@JRubyMethod(name = "uniq!") public IRubyObject uniq_bang19(ThreadContext context, Block block) { modifyCheck(); if (!block.isGiven()) return uniq_bang(context); RubyHash hash = makeHash(context, block); if (realLength == hash.size()) return context.nil; // after evaluating the block, a new modify check is needed modifyCheck(); // TODO: (CON) This could be a no-op for packed arrays if size does not change unpack(); realLength = 0; hash.visitAll(context, RubyHash.StoreValueVisitor, this); return this; }
@JRubyMethod(name = "uniq!") public IRubyObject uniq_bang19(ThreadContext context, Block block) { modifyCheck(); if (!block.isGiven()) return uniq_bang(context); RubyHash hash = makeHash(context, block); if (realLength == hash.size()) return context.nil; // after evaluating the block, a new modify check is needed modifyCheck(); // TODO: (CON) This could be a no-op for packed arrays if size does not change unpack(); realLength = 0; hash.visitAll(context, RubyHash.StoreValueVisitor, this); return this; }