@Specialization public RubyHash construct(Object[] args) { final RubyHash hash = new RubyHash(getContext().getCoreLibrary().getHashClass()); if (args.length == 1) { final RubyArray array = (RubyArray) args[0]; for (int n = 0; n < array.size(); n++) { final RubyArray keyValue = (RubyArray) array.get(n); hash.put(keyValue.get(0), keyValue.get(1)); } } else { if (args.length % 2 != 0) { // TODO(CS): figure out what error to throw here throw new UnsupportedOperationException(); } for (int n = 0; n < args.length; n += 2) { hash.put(args[n], args[n + 1]); } } return hash; }
@Specialization public Object construct(RubyHash hash, Object index, Object value) { hash.put(index, value); return value; }