本文整理汇总了Java中org.jruby.Ruby.newFixnum方法的典型用法代码示例。如果您正苦于以下问题:Java Ruby.newFixnum方法的具体用法?Java Ruby.newFixnum怎么用?Java Ruby.newFixnum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jruby.Ruby
的用法示例。
在下文中一共展示了Ruby.newFixnum方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: add
import org.jruby.Ruby; //导入方法依赖的package包/类
/**
* A ruby method that adds two numbers. In practice we would do some more
* complex operation in java possibly using a library method, or a pure java
* method of our own creation (possible private).
* @param context ThreadContext
* @param recv the receiver
* @param args array of input arguments
* @return The outcome of doing a plus b.
*/
@JRubyMethod(name = "add", module = true, rest = true)
public static IRubyObject add(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Ruby runtime = context.getRuntime();
// Arity.checkArgumentCount(runtime, args, Arity.OPTIONAL.getValue(), 2);
int a = (int) args[0].toJava(Integer.class);
int b = (int) args[1].toJava(Integer.class);
int result = a + b;
return runtime.newFixnum(result);
}
示例2: mult
import org.jruby.Ruby; //导入方法依赖的package包/类
/**
* Multiplies two numbers (in practice you would implement some method in java,
* probably using an external library)
* @param context ThreadContext
* @param args the ruby way of coping with more than two arguments
* @return result probably RubyFixnum
*/
@JRubyMethod(name = "multiply", rest = true)
public IRubyObject mult(ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.getRuntime();
// Arity.checkArgumentCount(runtime, args, Arity.OPTIONAL.getValue(), 2);
int a = (int) args[0].toJava(Integer.class);
int b = (int) args[1].toJava(Integer.class);
int result = a * b;
return runtime.newFixnum(result);
}