public RubyHash(Ruby runtime, IRubyObject defaultValue) { super(runtime, runtime.getHash()); this.ifNone = defaultValue; allocFirst(); }
public RubyHash(Ruby runtime, IRubyObject defaultValue) { super(runtime, runtime.getHash()); this.ifNone = defaultValue; allocFirst(); }
public RubyHash(Ruby runtime, IRubyObject defaultValue, int buckets) { super(runtime, runtime.getHash()); this.ifNone = defaultValue; allocFirst(buckets); }
public RubyHash(Ruby runtime, IRubyObject defaultValue) { super(runtime, runtime.getHash()); this.ifNone = defaultValue; allocFirst(); }
public RubyHash(Ruby runtime, IRubyObject defaultValue, int buckets) { super(runtime, runtime.getHash()); this.ifNone = defaultValue; if (buckets <= 0) buckets = 1; // FIXME: this hash implementation cannot deal with no buckets so we will add a single one (this constructor will go away once open addressing is added back). allocFirst(buckets); }
public static IRubyObject checkHashType(Ruby runtime, IRubyObject obj) { if (obj instanceof RubyHash) return obj; return TypeConverter.convertToTypeWithCheck(obj, runtime.getHash(), "to_hash"); }
public RubyHash(Ruby runtime, IRubyObject defaultValue, int buckets) { super(runtime, runtime.getHash()); this.ifNone = defaultValue; if (buckets <= 0) buckets = 1; // FIXME: this hash implementation cannot deal with no buckets so we will add a single one (this constructor will go away once open addressing is added back). allocFirst(buckets); }
public RubyHash(Ruby runtime, Map valueMap, IRubyObject defaultValue) { super(runtime, runtime.getHash()); this.ifNone = defaultValue; allocFirst(); for (Iterator iter = valueMap.entrySet().iterator();iter.hasNext();) { Map.Entry e = (Map.Entry)iter.next(); internalPut((IRubyObject)e.getKey(), (IRubyObject)e.getValue()); } }
public RubyHash(Ruby runtime, Map valueMap, IRubyObject defaultValue) { super(runtime, runtime.getHash()); this.ifNone = defaultValue; allocFirst(); for (Iterator iter = valueMap.entrySet().iterator();iter.hasNext();) { Map.Entry e = (Map.Entry)iter.next(); internalPut((IRubyObject)e.getKey(), (IRubyObject)e.getValue()); } }
/** * Tries to convert this object to a Ruby Hash using the "to_hash" * method. */ public RubyHash convertToHash() { return (RubyHash)TypeConverter.convertToType(this, getRuntime().getHash(), "to_hash"); }
private static IRubyObject toHash(ThreadContext context, IRubyObject lastArg) { if (lastArg instanceof RubyHash) return (RubyHash) lastArg; if (lastArg.respondsTo("to_hash")) { lastArg = lastArg.callMethod(context, "to_hash"); if (lastArg == context.nil) return lastArg; TypeConverter.checkType(context, lastArg, context.runtime.getHash()); return (RubyHash) lastArg; } return null; }
private static IRubyObject toHash(ThreadContext context, IRubyObject lastArg) { if (lastArg instanceof RubyHash) return (RubyHash) lastArg; if (lastArg.respondsTo("to_hash")) { lastArg = lastArg.callMethod(context, "to_hash"); if (lastArg == context.nil) return lastArg; TypeConverter.checkType(context, lastArg, context.runtime.getHash()); return (RubyHash) lastArg; } return null; }
@JRubyMethod public RubyHash to_h(ThreadContext context) { final Ruby runtime = context.runtime; return getType() == runtime.getHash() ? this : newHash(runtime).replace(context, this); }
/** * Tries to convert this object to a Ruby Hash using the "to_hash" method. * @return hash representation of this */ @Override public RubyHash convertToHash() { Ruby runtime = getRuntime(); ThreadContext context = runtime.getCurrentContext(); BasicObjectSites sites = sites(context); return (RubyHash) TypeConverter.convertToType(context, this, runtime.getHash(), sites.to_hash_checked); }
private String formatMessage(final IRubyObject msg) { if (getRuntime().getString().equals(msg.getType())) { return msg.asJavaString(); } else if (getRuntime().getHash().equals(msg.getType())) { final RubyHash hash = (RubyHash) msg; return Objects.toString(hash.get(getRuntime().newSymbol(LOG_PROPERTY_TEXT))); } throw new IllegalArgumentException(Objects.toString(msg)); }
private String formatMessage(final IRubyObject msg) { if (getRuntime().getString().equals(msg.getType())) { return msg.asJavaString(); } else if (getRuntime().getHash().equals(msg.getType())) { final RubyHash hash = (RubyHash) msg; return Objects.toString(hash.get(getRuntime().newSymbol(LOG_PROPERTY_TEXT))); } throw new IllegalArgumentException(Objects.toString(msg)); }
private Cursor getSourceLocation(IRubyObject msg) { if (getRuntime().getHash().equals(msg.getType())) { final RubyHash hash = (RubyHash) msg; final Object sourceLocation = hash.get(getRuntime().newSymbol(LOG_PROPERTY_SOURCE_LOCATION)); return new CursorImpl((IRubyObject) sourceLocation); } return null; } }
private Cursor getSourceLocation(IRubyObject msg) { if (getRuntime().getHash().equals(msg.getType())) { final RubyHash hash = (RubyHash) msg; final Object sourceLocation = hash.get(getRuntime().newSymbol(LOG_PROPERTY_SOURCE_LOCATION)); return new CursorImpl((IRubyObject) sourceLocation); } return null; } }
@JRubyMethod(name = "sub!", reads = BACKREF, writes = BACKREF) public IRubyObject sub_bang(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) { Ruby runtime = context.runtime; IRubyObject hash = TypeConverter.convertToTypeWithCheck(context, arg1, runtime.getHash(), sites(context).to_hash_checked); frozenCheck(); if (hash == context.nil) { return subBangNoIter(context, asRegexpArg(runtime, arg0), arg1.convertToString()); } return subBangIter(context, asRegexpArg(runtime, arg0), (RubyHash) hash, block); }
@JRubyMethod(name = "sub!", reads = BACKREF, writes = BACKREF) public IRubyObject sub_bang(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) { Ruby runtime = context.runtime; IRubyObject hash = TypeConverter.convertToTypeWithCheck(context, arg1, runtime.getHash(), sites(context).to_hash_checked); frozenCheck(); if (hash == context.nil) { return subBangNoIter(context, asRegexpArg(runtime, arg0), arg1.convertToString()); } return subBangIter(context, asRegexpArg(runtime, arg0), (RubyHash) hash, block); }