public Object max(VirtualFrame frame, RubyArray array) {
// TODO: can we just write to the frame instead of having this indirect object?
final Memo<Object> maximum = new Memo<>();
final VirtualFrame maximumClosureFrame = Truffle.getRuntime().createVirtualFrame(RubyArguments.pack(maxBlock, null, array, null, new Object[]{}), maxBlock.getFrameDescriptor());
maximumClosureFrame.setObject(maxBlock.getFrameSlot(), maximum);
final RubyProc block = new RubyProc(getContext().getCoreLibrary().getProcClass(), RubyProc.Type.PROC,
maxBlock.getSharedMethodInfo(), maxBlock.getCallTarget(), maxBlock.getCallTarget(),
maximumClosureFrame.materialize(), array, null);
eachNode.call(frame, array, "each", block);
if (maximum.get() == null) {
return getContext().getCoreLibrary().getNilObject();