Beispiel #1
0
    @Specialization
    public RubyArray toArray(RubyHash hash) {
      final RubyArray array = new RubyArray(getContext().getCoreLibrary().getArrayClass());

      for (Object key : hash.storage.keySet()) {
        RubyArray subArray = new RubyArray(getContext().getCoreLibrary().getArrayClass());

        subArray.push(key);
        subArray.push(hash.storage.get(key));
        array.push(subArray);
      }
      return array;
    }
Beispiel #2
0
    @Specialization
    public RubyArray values(RubyHash hash) {
      final RubyArray array = new RubyArray(getContext().getCoreLibrary().getArrayClass());

      for (Object value : hash.storage.values()) {
        array.push(value);
      }

      return array;
    }
Beispiel #3
0
    @Specialization
    public RubyArray map(VirtualFrame frame, RubyHash hash, RubyProc block) {
      final RubyArray result = new RubyArray(getContext().getCoreLibrary().getArrayClass());

      for (Map.Entry<Object, Object> entry : hash.storage.entrySet()) {
        result.push(yield(frame, block, entry.getKey(), entry.getValue()));
      }

      return result;
    }