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: 7118975f2ca1
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d814c8cfb2c4
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Aug 21, 2017

  1. Copy the full SHA
    11df47a View commit details
  2. Copy the full SHA
    d814c8c View commit details
73 changes: 33 additions & 40 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -533,12 +533,12 @@ public final RubyClass getMetaClass() {
*/
@Override
public RubyClass getSingletonClass() {
RubyClass klass;
RubyClass klass = getMetaClass();

if (getMetaClass().isSingleton() && ((MetaClass)getMetaClass()).getAttached() == this) {
klass = getMetaClass();
if (klass.isSingleton() && ((MetaClass) klass).getAttached() == this) {
// no-op
} else {
klass = makeMetaClass(getMetaClass());
klass = makeMetaClass(klass);
}

klass.setTaint(isTaint());
@@ -601,10 +601,9 @@ public final boolean respondsTo(String name) {

final ThreadContext context = runtime.getCurrentContext();
final RubySymbol mname = runtime.newSymbol(name);
final boolean respondToUndefined = respondTo.isUndefined();

// respond_to? or respond_to_missing? is not defined, so we must dispatch to trigger method_missing
if ( respondToUndefined ) {
if ( respondTo.isUndefined() ) {
return sites(context).respond_to.call(context, this, this, mname).isTrue();
}

@@ -659,14 +658,14 @@ public final Ruby getRuntime() {

/**
* Will return the Java interface that most closely can represent
* this object, when working through JAva integration
* translations.
* this object, when working through Java integration translations.
* @return the true Java class of this (Ruby) object
*/
@Override
public Class getJavaClass() {
Object obj = dataGetStruct();
if (obj instanceof JavaObject) {
return ((JavaObject)obj).getValue().getClass();
return ((JavaObject) obj).getValue().getClass();
}
return getClass();
}
@@ -676,13 +675,13 @@ public Class getJavaClass() {
* Will try to convert this object to a String using the Ruby
* "to_str" if the object isn't already a String. If this still
* doesn't work, will throw a Ruby TypeError.
*
* @return a (Java) string
*/
@Override
public String asJavaString() {
IRubyObject asString = checkStringType();
if(!asString.isNil()) return ((RubyString)asString).asJavaString();
throw getRuntime().newTypeError(inspect().toString() + " is not a string");
IRubyObject str = checkStringType();
if (!str.isNil()) return ((RubyString) str).asJavaString();
throw getRuntime().newTypeError(inspect() + " is not a string");
}

/** rb_obj_as_string
@@ -699,14 +698,14 @@ public RubyString asString() {
BasicObjectSites sites = sites(context);
IRubyObject str = sites.to_s.call(context, this, this);

if (!(str instanceof RubyString)) return (RubyString)anyToString();
if (!(str instanceof RubyString)) return (RubyString) anyToString();
if (isTaint()) str.setTaint(true);
return (RubyString) str;
}

/**
* Tries to convert this object to a Ruby Array using the "to_ary"
* method.
* Tries to convert this object to a Ruby Array using the "to_ary" method.
* @return array representation of this
*/
@Override
public RubyArray convertToArray() {
@@ -717,8 +716,8 @@ public RubyArray convertToArray() {
}

/**
* Tries to convert this object to a Ruby Hash using the "to_hash"
* method.
* Tries to convert this object to a Ruby Hash using the "to_hash" method.
* @return hash representation of this
*/
@Override
public RubyHash convertToHash() {
@@ -729,8 +728,8 @@ public RubyHash convertToHash() {
}

/**
* Tries to convert this object to a Ruby Float using the "to_f"
* method.
* Tries to convert this object to a Ruby Float using the "to_f" method.
* @return float representation of this
*/
@Override
public RubyFloat convertToFloat() {
@@ -741,8 +740,8 @@ public RubyFloat convertToFloat() {
}

/**
* Tries to convert this object to a Ruby Integer using the "to_int"
* method.
* Tries to convert this object to a Ruby Integer using the "to_int" method.
* @return an integer representation of this
*/
@Override
public RubyInteger convertToInteger() {
@@ -760,8 +759,9 @@ public RubyInteger convertToInteger() {
}

/**
* Tries to convert this object to a Ruby Integer using the
* supplied conversion method.
* Tries to convert this object to a Ruby Integer using the supplied conversion method.
* @param convertMethod conversion method to use e.g. "to_i"
* @return an integer representation of this
*/
@Override
public RubyInteger convertToInteger(String convertMethod) {
@@ -785,15 +785,15 @@ public RubyInteger convertToInteger(String convertMethod) {
}

/**
* Tries to convert this object to a Ruby String using the
* "to_str" method.
* Tries to convert this object to a Ruby String using the "to_str" method.
* @return a string representation of this
*/
@Override
public RubyString convertToString() {
Ruby runtime = getRuntime();
ThreadContext context = runtime.getCurrentContext();
BasicObjectSites sites = sites(context);
return (RubyString) TypeConverter.convertToType(context, this, getRuntime().getString(), sites.to_str_checked);
return (RubyString) TypeConverter.convertToType(context, this, runtime.getString(), sites.to_str_checked);
}

/**
@@ -831,22 +831,18 @@ public IRubyObject checkStringType() {
return TypeConverter.checkStringType(context, sites.to_str_checked, this);
}

/** rb_check_string_type
*
* Tries to return a coerced string representation of this object,
* using "to_str". If that returns something other than a String
* or nil, an empty String will be returned.
*
/**
* @deprecated
* @see #checkStringType()
*/
@Override
public IRubyObject checkStringType19() {
public final IRubyObject checkStringType19() {
return checkStringType();
}

/** rb_check_array_type
*
* Returns the result of trying to convert this object to an Array
* with "to_ary".
* Returns the result of trying to convert this object to an Array with "to_ary".
*/
@Override
public IRubyObject checkArrayType() {
@@ -895,15 +891,14 @@ else if (target.isAssignableFrom(getClass())) {

@Override
public IRubyObject dup() {
Ruby runtime = getRuntime();

if (isSpecialObject()) {
return this;
}

IRubyObject dup = getMetaClass().getRealClass().allocate();
if (isTaint()) dup.setTaint(true);

final Ruby runtime = getRuntime();
initCopy(runtime.getCurrentContext(), dup, this, false);

return dup;
@@ -1148,8 +1143,6 @@ public IRubyObject inspect() {
if ((!isImmediate()) && !(this instanceof RubyModule) && hasVariables()) {
return hashyInspect();
}

if (isNil()) return RubyNil.inspect(getRuntime());
return to_s();
}

7 changes: 4 additions & 3 deletions core/src/main/java/org/jruby/RubyNil.java
Original file line number Diff line number Diff line change
@@ -118,7 +118,7 @@ public Class<?> getJavaClass() {
public Object constant() {
return constant;
}

// Methods of the Nil Class (nil_*):

/** nil_to_i
@@ -162,9 +162,10 @@ public static RubyHash to_h(ThreadContext context, IRubyObject recv) {
/** nil_inspect
*
*/
@Override
@JRubyMethod
public static RubyString inspect(ThreadContext context, IRubyObject recv) {
return inspect(context.runtime);
public IRubyObject inspect() {
return RubyNil.inspect(getRuntime());
}

static final byte[] nilBytes = new byte[] { 'n','i','l' }; // RubyString.newUSASCIIString(runtime, "nil")
Original file line number Diff line number Diff line change
@@ -325,6 +325,7 @@ public interface IRubyObject {
* @return the object wrapped.
*/
Object dataGetStruct();
@Deprecated // not used at all
Object dataGetStructChecked();

/**