本文整理汇总了Java中org.jruby.runtime.builtin.IRubyObject.toString方法的典型用法代码示例。如果您正苦于以下问题:Java IRubyObject.toString方法的具体用法?Java IRubyObject.toString怎么用?Java IRubyObject.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jruby.runtime.builtin.IRubyObject
的用法示例。
在下文中一共展示了IRubyObject.toString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setName
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
/**
* This method allows the user to set the name of the alias of the FieldSchema of the encapsulated
* Schema. This method only works if the Schema has one FieldSchema.
*
* @param arg a RubyString to set the name to
* @return the new name
*/
@JRubyMethod(name = "name=")
public RubyString setName(IRubyObject arg) {
if (arg instanceof RubyString) {
if (internalSchema.size() != 1)
throw new RuntimeException("Can only set name if there is one schema present");
try {
internalSchema.getField(0).alias = arg.toString();
return (RubyString)arg;
} catch (FrontendException e) {
throw new RuntimeException("Unable to get field from Schema", e);
}
} else {
throw new RuntimeException("Improper argument passed to 'name=':" + arg);
}
}
示例2: get
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
/**
* This is a version of [] which allows the range to be specified as such: [1,2].
*
* @param context the context the method is being executed in
* @param arg1 a Fixnum start index
* @param arg2 a Fixnum end index
* @return the RubySchema object encapsulated the found Schema
*/
@JRubyMethod(name = {"[]", "slice"})
public RubySchema get(ThreadContext context, IRubyObject arg1, IRubyObject arg2) {
if (arg1 instanceof RubyFixnum && arg2 instanceof RubyFixnum) {
Ruby runtime = context.getRuntime();
int min = (int)((RubyFixnum)arg1).getLongValue();
int max = (int)((RubyFixnum)arg2).getLongValue() - 1;
return new RubySchema(runtime, runtime.getClass("Schema"), new Schema(internalSchema.getFields().subList(min, max + 1)), false);
} else {
throw new RuntimeException("Bad arguments given to get function: ( " + arg1.toString() + " , " + arg2.toString()+ " )");
}
}
示例3: set
import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
/**
* This allows the users to set an index or a range of values to
* a specified RubySchema. The first argument must be a Fixnum or Range,
* and the second argument may optionally be a Fixnum. The given index
* (or range of indices) will be replaced by a RubySchema instantiated
* based on the remaining arguments.
*
* @param context the contextthe method is being executed in
* @param args a varargs which has to be at least length two.
* @return the RubySchema that was added
*/
@JRubyMethod(name = {"[]=", "set"}, required = 2, rest = true)
public RubySchema set(ThreadContext context, IRubyObject[] args) {
IRubyObject arg1 = args[0];
IRubyObject arg2 = args[1];
IRubyObject[] arg3 = Arrays.copyOfRange(args, 1, args.length);
Schema s = internalSchema;
Ruby runtime = context.getRuntime();
List<Schema.FieldSchema> lfs = s.getFields();
int min, max;
if (arg1 instanceof RubyFixnum && arg2 instanceof RubyFixnum) {
min = (int)((RubyFixnum)arg1).getLongValue();
max = (int)((RubyFixnum)arg2).getLongValue();
arg3 = Arrays.copyOfRange(args, 2, args.length);
} else if (arg1 instanceof RubyFixnum) {
min = (int)((RubyFixnum)arg1).getLongValue();
max = min + 1;
} else if (arg1 instanceof RubyRange) {
min = (int)((RubyFixnum)((RubyRange)arg1).min(context, Block.NULL_BLOCK)).getLongValue();
max = (int)((RubyFixnum)((RubyRange)arg1).max(context, Block.NULL_BLOCK)).getLongValue() + 1;
} else {
throw new RuntimeException("Bad arguments given to get function: ( " + arg1.toString() + " , " + arg2.toString()+ " )");
}
for (int i = min; i < max; i++)
lfs.remove(min);
if (arg3 == null || arg3.length == 0)
throw new RuntimeException("Must have schema argument for []=");
RubySchema rs = new RubySchema(runtime, runtime.getClass("Schema")).initialize(arg3);
for (Schema.FieldSchema fs : rs.getInternalSchema().getFields())
lfs.add(min++, fs);
RubySchema.fixSchemaNames(internalSchema);
return rs;
}