Permalink
Browse files

Implement Kernel#Hash. Fixes JRUBY-6496.

  • Loading branch information...
1 parent c3346bf commit 677cf1bd460e9154e78290b31392d0e5c9bce20e @BanzaiMan BanzaiMan committed Mar 27, 2012
Showing with 15 additions and 0 deletions.
  1. +15 −0 src/org/jruby/RubyKernel.java
@@ -397,6 +397,21 @@ public static RubyFloat new_float19(IRubyObject recv, IRubyObject object) {
return (RubyFloat)TypeConverter.convertToType19(object, runtime.getFloat(), "to_f");
}
}
+
+ @JRubyMethod(name = "Hash", required = 1, module = true, visibility = PRIVATE, compat = RUBY1_9)
+ public static IRubyObject new_hash(ThreadContext context, IRubyObject recv, IRubyObject arg) {
+ IRubyObject tmp;
+ Ruby runtime = recv.getRuntime();
+ if (arg.isNil()) return RubyHash.newHash(runtime);
+ tmp = TypeConverter.checkHashType(runtime, arg);
+ if (tmp.isNil()) {
+ if (arg instanceof RubyArray && ((RubyArray) arg).isEmpty()) {
+ return RubyHash.newHash(runtime);
+ }
+ throw runtime.newTypeError("can't convert " + arg.getMetaClass() + " into Hash");
+ }
+ return tmp;
+ }
@JRubyMethod(name = "Integer", required = 1, module = true, visibility = PRIVATE, compat = RUBY1_8)
public static IRubyObject new_integer(ThreadContext context, IRubyObject recv, IRubyObject object) {

0 comments on commit 677cf1b

Please sign in to comment.