Beispiel #1
0
  public static RubyArray convertToRubyArrayWithCoerce(Ruby runtime, IRubyObject value) {
    if (value instanceof RubyArray) return ((RubyArray) value);

    IRubyObject newValue = TypeConverter.convertToType(value, runtime.getArray(), "to_ary", false);

    if (newValue.isNil()) {
      return RubyArray.newArrayLight(runtime, value);
    }

    // empirically it appears that to_ary coersions always return array or nil, so this
    // should always be an array by now.
    return (RubyArray) newValue;
  }
Beispiel #2
0
  public static RubyArray convertToRubyArrayWithCoerce(Ruby runtime, IRubyObject value) {
    if (value instanceof RubyArray) return ((RubyArray) value);

    IRubyObject newValue = TypeConverter.convertToType(value, runtime.getArray(), "to_ary", false);

    if (newValue.isNil()) {
      return RubyArray.newArrayLight(runtime, value);
    }

    // must be array by now, or error
    if (!(newValue instanceof RubyArray)) {
      throw runtime.newTypeError(newValue.getMetaClass() + "#" + "to_ary" + " should return Array");
    }

    return (RubyArray) newValue;
  }