Exemplo n.º 1
0
    @Specialization
    public Object delete(RubyHash hash, Object index) {
      hash.checkFrozen();

      final Object value = hash.getMap().remove(index);

      if (value == null) {
        return NilPlaceholder.INSTANCE;
      } else {
        return value;
      }
    }
Exemplo n.º 2
0
    @Specialization
    public Object construct(VirtualFrame frame, RubyHash hash, Object index) {
      final Object value = hash.get(index);

      if (value == null) {
        if (hash.defaultBlock == null) {
          return NilPlaceholder.INSTANCE;
        } else {
          return hash.defaultBlock.call(frame.pack(), hash, index);
        }
      } else {
        return value;
      }
    }
Exemplo n.º 3
0
    @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;
    }
Exemplo n.º 4
0
 @Specialization
 public Object construct(RubyHash hash, Object index, Object value) {
   hash.put(index, value);
   return value;
 }
Exemplo n.º 5
0
 @Specialization
 public NilPlaceholder initialize(RubyHash hash, RubyProc block) {
   hash.initialize(block);
   return NilPlaceholder.INSTANCE;
 }
Exemplo n.º 6
0
 @Specialization
 public NilPlaceholder initialize(
     RubyHash hash, @SuppressWarnings("unused") UndefinedPlaceholder block) {
   hash.initialize(null);
   return NilPlaceholder.INSTANCE;
 }