Created
January 14, 2020 15:51
-
-
Save headius/511632d8f3b6aeb2348462b42556b410 to your computer and use it in GitHub Desktop.
Change RubyBasicObject.to_a to IRubyObject return
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/core/src/main/java/org/jruby/RubyBasicObject.java b/core/src/main/java/org/jruby/RubyBasicObject.java | |
index 5ec44d5129..c0e5121211 100644 | |
--- a/core/src/main/java/org/jruby/RubyBasicObject.java | |
+++ b/core/src/main/java/org/jruby/RubyBasicObject.java | |
@@ -2571,7 +2571,7 @@ public class RubyBasicObject implements Cloneable, IRubyObject, Serializable, Co | |
* | |
* The default to_a method is deprecated. | |
*/ | |
- public RubyArray to_a(ThreadContext context) { | |
+ public IRubyObject to_a(ThreadContext context) { | |
Ruby runtime = context.runtime; | |
runtime.getWarnings().warn(ID.DEPRECATED_METHOD, "default 'to_a' will be obsolete"); | |
return runtime.newArray(this); | |
@@ -3228,7 +3228,7 @@ public class RubyBasicObject implements Cloneable, IRubyObject, Serializable, Co | |
@Deprecated | |
public RubyArray to_a() { | |
- return to_a(getRuntime().getCurrentContext()); | |
+ return to_a(getRuntime().getCurrentContext()).convertToArray(); | |
} | |
@Deprecated | |
diff --git a/core/src/main/java/org/jruby/RubyHash.java b/core/src/main/java/org/jruby/RubyHash.java | |
index d6658775be..3ee861358c 100644 | |
--- a/core/src/main/java/org/jruby/RubyHash.java | |
+++ b/core/src/main/java/org/jruby/RubyHash.java | |
@@ -916,7 +916,7 @@ public class RubyHash extends RubyObject implements Map { | |
*/ | |
@JRubyMethod(name = "to_a") | |
@Override | |
- public RubyArray to_a(ThreadContext context) { | |
+ public IRubyObject to_a(ThreadContext context) { | |
final Ruby runtime = context.runtime; | |
try { | |
final RubyArray result = RubyArray.newBlankArrayInternal(runtime, size); | |
@@ -1582,7 +1582,7 @@ public class RubyHash extends RubyObject implements Map { | |
@Deprecated | |
public IRubyObject sort(ThreadContext context, Block block) { | |
- return to_a(context).sort_bang(context, block); | |
+ return to_a(context).convertToArray().sort_bang(context, block); | |
} | |
/** rb_hash_index | |
@@ -2046,14 +2046,14 @@ public class RubyHash extends RubyObject implements Map { | |
@JRubyMethod | |
public IRubyObject flatten(ThreadContext context) { | |
- RubyArray ary = to_a(context); | |
+ RubyArray ary = to_a(context).convertToArray(); | |
sites(context).flatten_bang.call(context, ary, ary, RubyFixnum.one(context.runtime)); | |
return ary; | |
} | |
@JRubyMethod | |
public IRubyObject flatten(ThreadContext context, IRubyObject level) { | |
- RubyArray ary = to_a(context); | |
+ RubyArray ary = to_a(context).convertToArray(); | |
sites(context).flatten_bang.call(context, ary, ary, level); | |
return ary; | |
} | |
@@ -2754,7 +2754,7 @@ public class RubyHash extends RubyObject implements Map { | |
@Deprecated | |
@Override | |
public RubyArray to_a() { | |
- return to_a(getRuntime().getCurrentContext()); | |
+ return to_a(getRuntime().getCurrentContext()).convertToArray(); | |
} | |
@Deprecated | |
diff --git a/core/src/main/java/org/jruby/RubyMatchData.java b/core/src/main/java/org/jruby/RubyMatchData.java | |
index 00cf222c5c..1bd545a6a8 100644 | |
--- a/core/src/main/java/org/jruby/RubyMatchData.java | |
+++ b/core/src/main/java/org/jruby/RubyMatchData.java | |
@@ -584,7 +584,7 @@ public class RubyMatchData extends RubyObject { | |
public IRubyObject op_aref(ThreadContext context, IRubyObject idx) { | |
check(); | |
IRubyObject result = op_arefCommon(idx); | |
- return result == null ? to_a(context).aref(idx) : result; | |
+ return result == null ? to_a(context).convertToArray().aref(idx) : result; | |
} | |
/** match_aref | |
@@ -593,7 +593,7 @@ public class RubyMatchData extends RubyObject { | |
@JRubyMethod(name = "[]") | |
public IRubyObject op_aref(ThreadContext context, IRubyObject idx, IRubyObject rest) { | |
IRubyObject result; | |
- return !rest.isNil() || (result = op_arefCommon(idx)) == null ? to_a(context).aref(idx, rest) : result; | |
+ return !rest.isNil() || (result = op_arefCommon(idx)) == null ? to_a(context).convertToArray().aref(idx, rest) : result; | |
} | |
private IRubyObject op_arefCommon(IRubyObject idx) { | |
diff --git a/core/src/main/java/org/jruby/ext/set/RubySet.java b/core/src/main/java/org/jruby/ext/set/RubySet.java | |
index 0db99dcc7c..3195dc5f6a 100644 | |
--- a/core/src/main/java/org/jruby/ext/set/RubySet.java | |
+++ b/core/src/main/java/org/jruby/ext/set/RubySet.java | |
@@ -695,7 +695,7 @@ public class RubySet extends RubyObject implements Set { | |
return enumeratorizeWithSize(context, this, "collect!", enumSize()); | |
} | |
- final RubyArray elems = to_a(context); clearImpl(); | |
+ final RubyArray elems = to_a(context).convertToArray(); clearImpl(); | |
for ( int i=0; i<elems.size(); i++ ) { | |
addImpl(context.runtime, block.yield(context, elems.eltInternal(i))); | |
} | |
diff --git a/core/src/main/java/org/jruby/java/proxies/MapJavaProxy.java b/core/src/main/java/org/jruby/java/proxies/MapJavaProxy.java | |
index 9dad20d598..6d9162e27f 100644 | |
--- a/core/src/main/java/org/jruby/java/proxies/MapJavaProxy.java | |
+++ b/core/src/main/java/org/jruby/java/proxies/MapJavaProxy.java | |
@@ -139,7 +139,7 @@ public final class MapJavaProxy extends ConcreteJavaProxy { | |
@Override | |
public RubyArray to_a(ThreadContext context) { | |
syncSize(); | |
- return super.to_a(context); | |
+ return super.to_a(context).convertToArray(); | |
} | |
@Override | |
@@ -468,7 +468,7 @@ public final class MapJavaProxy extends ConcreteJavaProxy { | |
@Override | |
@JRubyMethod(name = "to_a") | |
public RubyArray to_a(ThreadContext context) { | |
- return getOrCreateRubyHashMap(context.runtime).to_a(context); | |
+ return getOrCreateRubyHashMap(context.runtime).to_a(context).convertToArray(); | |
} | |
@JRubyMethod(name = "to_proc") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment