@Override public boolean equals(Object obj) { if ( obj instanceof ArrayJavaProxy ) { final ArrayJavaProxy that = (ArrayJavaProxy) obj; final Object thisArray = this.getObject(); final Object thatArray = that.getObject(); return arraysEquals(thisArray, thatArray); } return false; }
@Override public final Object dataGetStruct() { if (javaObject == null) { javaObject = asJavaObject(object); } return javaObject; }
private static String unwrapJavaString(IRubyObject arg) { if (arg instanceof JavaProxy) { Object str = ((JavaProxy) arg).getObject(); return str instanceof String ? (String) str : null; } return null; }
/** rb_hash_inspect * */ @JRubyMethod(name = "inspect") public IRubyObject inspect(ThreadContext context) { return getOrCreateRubyHashMap().inspect(context); }
/** rb_hash_to_a * */ @JRubyMethod(name = "to_a") public RubyArray to_a() { return getOrCreateRubyHashMap().to_a(); }
/** rb_hash_to_s * */ @JRubyMethod(name = "to_s") public IRubyObject to_s(ThreadContext context) { return getOrCreateRubyHashMap().to_s(context); }
/** rb_hash_equal * */ @JRubyMethod(name = "==") public IRubyObject op_equal(final ThreadContext context, IRubyObject other) { return getOrCreateRubyHashMap().op_equal(context, other); }
/** rb_hash_each_key * */ @JRubyMethod(name = "each_key") public IRubyObject each_key(final ThreadContext context, final Block block) { return getOrCreateRubyHashMap().each_key(context, block); }
/** rb_hash_select_bang * */ @JRubyMethod(name = "select!") public IRubyObject select_bang(final ThreadContext context, final Block block) { return getOrCreateRubyHashMap().select_bang(context, block); }
/** rb_hash_shift * */ @JRubyMethod(name = "shift", notImplemented = true) public IRubyObject shift(ThreadContext context) { return getOrCreateRubyHashMap().shift(context); }
/** rb_hash_to_hash * */ @JRubyMethod(name = { "to_hash", "to_h" }) public RubyHash to_hash() { return getOrCreateRubyHashMap().to_hash(); }
/** rb_hash_each * */ @JRubyMethod(name = {"each", "each_pair"}) public IRubyObject each(final ThreadContext context, final Block block) { return getOrCreateRubyHashMap().each(context, block); }
/** rb_hash_key * */ @JRubyMethod(name = "key") public IRubyObject key(ThreadContext context, IRubyObject expected) { return getOrCreateRubyHashMap().key(context, expected); }
/** rb_hash_keys * */ @JRubyMethod(name = "keys") public RubyArray keys(ThreadContext context) { return getOrCreateRubyHashMap().keys(context); }
/** rb_hash_delete * */ @JRubyMethod(name = "delete") public IRubyObject delete(ThreadContext context, IRubyObject key, Block block) { return getOrCreateRubyHashMap().delete(context, key, block); }
/** rb_hash_initialize_copy * */ @JRubyMethod(name = "initialize_copy", visibility = Visibility.PRIVATE) public RubyHash initialize_copy(ThreadContext context, IRubyObject other) { return getOrCreateRubyHashMap().initialize_copy(context, other); }
/** rb_hash_replace * */ @JRubyMethod(name = { "replace", "ruby_replace" }, required = 1) // collision with java.util.Map#replace on Java 8+ public RubyHash replace(final ThreadContext context, IRubyObject other) { return getOrCreateRubyHashMap().replace(context, other); }
/** rb_hash_values_at * */ @JRubyMethod(name = "values_at", rest = true) public RubyArray values_at(ThreadContext context, IRubyObject[] args) { return getOrCreateRubyHashMap().values_at(context, args); }
/** rb_hash_eql * */ @JRubyMethod(name = "eql?") public IRubyObject op_eql(final ThreadContext context, IRubyObject other) { return getOrCreateRubyHashMap().op_eql(context, other); }
protected static void initialize(final RubyClass ConcreteJavaProxy) { ConcreteJavaProxy.addMethod("initialize", new InitializeMethod(ConcreteJavaProxy)); // We define a custom "new" method to ensure that __jcreate! is getting called, // so that if the user doesn't call super in their subclasses, the object will // still get set up properly. See JRUBY-4704. RubyClass singleton = ConcreteJavaProxy.getSingletonClass(); singleton.addMethod("new", new NewMethod(singleton)); }