Exemple #1
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;
      }
    }
  @Override
  public Object execute(VirtualFrame frame) {
    final RubyArguments rubyArguments = frame.getArguments(RubyArguments.class);

    final Object[] arguments = rubyArguments.getArguments();

    final RubyClass arrayClass = getContext().getCoreLibrary().getArrayClass();

    if (arguments.length <= index) {
      return new RubyArray(arrayClass);
    } else if (index == 0) {
      return new RubyArray(arrayClass, new ObjectArrayStore(arguments));
    } else {
      return new RubyArray(
          arrayClass, new ObjectArrayStore(Arrays.copyOfRange(arguments, index, arguments.length)));
    }
  }