示例#1
0
文件: HashNodes.java 项目: phs/jruby
    @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;
      }
    }
示例#2
0
文件: HashNodes.java 项目: phs/jruby
    @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;
      }
    }
示例#3
0
文件: HashNodes.java 项目: phs/jruby
    @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;
    }
示例#4
0
文件: HashNodes.java 项目: phs/jruby
 @Specialization
 public Object construct(RubyHash hash, Object index, Object value) {
   hash.put(index, value);
   return value;
 }
示例#5
0
文件: HashNodes.java 项目: phs/jruby
 @Specialization
 public NilPlaceholder initialize(RubyHash hash, RubyProc block) {
   hash.initialize(block);
   return NilPlaceholder.INSTANCE;
 }
示例#6
0
文件: HashNodes.java 项目: phs/jruby
 @Specialization
 public NilPlaceholder initialize(
     RubyHash hash, @SuppressWarnings("unused") UndefinedPlaceholder block) {
   hash.initialize(null);
   return NilPlaceholder.INSTANCE;
 }