Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6ffbfc9934d4
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0d4e9f7dec19
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Dec 26, 2014

  1. Copy the full SHA
    e435c21 View commit details
  2. Copy the full SHA
    c400f2d View commit details

Commits on Jan 12, 2015

  1. Merge branch 'string_end_with_implicit_conversion' of https://github.…

    …com/lumeet/jruby into lumeet-string_end_with_implicit_conversion
    
    Conflicts:
    	core/src/main/java/org/jruby/RubyString.java
    headius committed Jan 12, 2015
    Copy the full SHA
    0d4e9f7 View commit details
Showing with 22 additions and 18 deletions.
  1. +2 −16 core/src/main/java/org/jruby/RubyString.java
  2. +20 −2 core/src/main/java/org/jruby/util/TypeConverter.java
18 changes: 2 additions & 16 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -3903,10 +3903,7 @@ public IRubyObject start_with_p(ThreadContext context, IRubyObject[]args) {
}

private boolean start_with_pCommon(IRubyObject arg) {
Ruby runtime = getRuntime();
RubyString otherString;

otherString = arg.convertToString();
RubyString otherString = arg.convertToString();

checkEncoding(otherString);

@@ -3941,18 +3938,7 @@ public IRubyObject end_with_p(ThreadContext context, IRubyObject[]args) {
}

private boolean end_with_pCommon(IRubyObject arg) {
Ruby runtime = getRuntime();
RubyString otherString;

if (!runtime.is2_0()) {
// 1.8 and 1.9 ignores uncoercible argument
IRubyObject tmp = arg.checkStringType();
if (tmp.isNil()) return false;
otherString = (RubyString) tmp;
} else {
// 2.0+ requires coersion to succeed
otherString = arg.convertToString();
}
RubyString otherString = arg.convertToString();

Encoding enc = checkEncoding(otherString);

22 changes: 20 additions & 2 deletions core/src/main/java/org/jruby/util/TypeConverter.java
Original file line number Diff line number Diff line change
@@ -46,7 +46,13 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

import java.util.Arrays;
import java.util.List;

public class TypeConverter {
private static final List<String> IMPLICIT_CONVERSIONS =
Arrays.asList("to_int", "to_ary", "to_str", "to_sym", "to_hash", "to_proc", "to_io");

/**
* Converts this object to type 'targetType' using 'convertMethod' method (MRI: convert_type).
*
@@ -57,8 +63,14 @@ public class TypeConverter {
* @return the converted value
*/
public static IRubyObject convertToType(IRubyObject obj, RubyClass target, String convertMethod, boolean raise) {
if (!obj.respondsTo(convertMethod)) return handleUncoercibleObject(raise, obj, target);

if (!obj.respondsTo(convertMethod)) {
if (IMPLICIT_CONVERSIONS.contains(convertMethod)) {
return handleImplicitlyUncoercibleObject(raise, obj, target);
} else {
return handleUncoercibleObject(raise, obj, target);
}
}

return obj.callMethod(obj.getRuntime().getCurrentContext(), convertMethod);
}

@@ -262,6 +274,12 @@ public static IRubyObject handleUncoercibleObject(boolean raise, IRubyObject obj
return obj.getRuntime().getNil();
}

public static IRubyObject handleImplicitlyUncoercibleObject(boolean raise, IRubyObject obj, RubyClass target) throws RaiseException {
if (raise) throw obj.getRuntime().newTypeError("no implicit conversion of " + typeAsString(obj) + " into " + target);

return obj.getRuntime().getNil();
}

// rb_check_type and Check_Type
public static void checkType(ThreadContext context, IRubyObject x, RubyModule t) {
ClassIndex xt;