/** * Copyright 2005-2007 Xue Yong Zhi * Distributed under the BSD License */ package com.xruby.runtime.builtin; import com.xruby.runtime.lang.RubyBinding; import com.xruby.runtime.lang.RubyBlock; import com.xruby.runtime.lang.RubyRuntime; import com.xruby.runtime.lang.RubyValue; import com.xruby.runtime.lang.RubyVarArgMethod; //import com.xruby.runtime.lang.annotation.RubyLevelClass; //import com.xruby.runtime.lang.annotation.RubyLevelMethod; import com.xruby.runtime.lang.RubyMethod; //@RubyLevelClass(name="Proc") public class RubyProc extends RubyBinding { private final RubyBlock value_; RubyProc(RubyBlock v) { super(RubyRuntime.ProcClass); setSelf(RubyRuntime.TOP_LEVEL_SELF_VALUE);//TODO should not hardcode this setScope(RubyRuntime.ObjectClass);//TODO should not hardcode this value_ = v; } //@RubyLevelMethod(name="new") public static RubyValue newProc(RubyValue receiver, RubyBlock block) { return ObjectFactory.createProc(block); } //@RubyLevelMethod(name="arity") public RubyFixnum arity() { return ObjectFactory.createFixnum(value_.arity()); } //@RubyLevelMethod(name="==", alias="eql?") public RubyValue equal(RubyValue v) { return ObjectFactory.createBoolean(equals(v)); } public boolean equals(Object o) { if (null == o) { return false; } else if (o instanceof RubyProc) { return value_ == ((RubyProc) o).value_; } else { return false; } } public RubyBlock getBlock() { return value_; } public boolean isDefinedInAnotherBlock() { return value_.isDefinedInAnotherBlock(); } private void setUpCallContext() { //TODO: setUpCallContext - reflection uses /* Field[] fields = value_.getClass().getFields(); // for (Field f : fields) { for(int i = 0; i