当前位置: 首页>>代码示例>>Java>>正文


Java Ruby.getClass方法代码示例

本文整理汇总了Java中org.jruby.Ruby.getClass方法的典型用法代码示例。如果您正苦于以下问题:Java Ruby.getClass方法的具体用法?Java Ruby.getClass怎么用?Java Ruby.getClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jruby.Ruby的用法示例。


在下文中一共展示了Ruby.getClass方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resultsCapturesJavaError

import org.jruby.Ruby; //导入方法依赖的package包/类
@Test(enabled = false) public void resultsCapturesJavaError() throws Exception {
    RubyScript script = new RubyScript(out, err, converToCode(SCRIPT_CONTENTS_ERROR_FROM_JAVA),
            new File(System.getProperty(Constants.PROP_PROJECT_DIR), "dummyfile.rb").getAbsolutePath(), false, null,
            Constants.FRAMEWORK_SWING);
    script.setDriverURL("");
    Ruby interpreter = script.getInterpreter();
    assertTrue("Collector not defined", interpreter.isClassDefined("Collector"));
    RubyClass collectorClass = interpreter.getClass("Collector");
    IRubyObject presult = JavaEmbedUtils.javaToRuby(interpreter, result);
    IRubyObject collector = collectorClass.newInstance(interpreter.getCurrentContext(), new IRubyObject[0], new Block(null));
    IRubyObject rubyObject = interpreter.evalScriptlet("proc { my_function }");
    try {
        collector.callMethod(interpreter.getCurrentContext(), "callprotected", new IRubyObject[] { rubyObject, presult });
    } catch (Throwable t) {

    }
    assertEquals(1, result.failureCount());
    Failure[] failures = result.failures();
    assertTrue("Should end with TestRubyScript.java. but has " + failures[0].getTraceback()[0].fileName,
            failures[0].getTraceback()[0].fileName.endsWith("TestRubyScript.java"));
    assertEquals("throwError", failures[0].getTraceback()[0].functionName);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:23,代码来源:RubyScriptTest.java

示例2: instantiateClass

import org.jruby.Ruby; //导入方法依赖的package包/类
/**
 * instantiateClass
 * 
 * @param runtime
 * @param name
 * @param args
 * @return
 */
public static IRubyObject instantiateClass(Ruby runtime, String name, IRubyObject... args)
{
	ThreadContext threadContext = runtime.getCurrentContext();
	IRubyObject result = null;

	// try to load the class
	RubyClass rubyClass = runtime.getClass(name);

	// instantiate it, if it exists
	if (rubyClass != null)
	{
		result = rubyClass.newInstance(threadContext, args, Block.NULL_BLOCK);
	}

	return result;
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:25,代码来源:ScriptUtils.java

示例3: tuple

import org.jruby.Ruby; //导入方法依赖的package包/类
/**
 * This is a ruby method which takes an array of arguments and constructs a Tuple schema from them. The name
 * will be set automatically.
 *
 * @param context the context the method is being executed in
 * @param self    the RubyClass for the Class object this was invoked on
 * @param arg     a list of arguments to instantiate the new RubySchema
 * @return        the new RubySchema
 */
@JRubyMethod(meta = true, name = {"t", "tuple"})
public static RubySchema tuple(ThreadContext context, IRubyObject self, IRubyObject arg) {
    if (arg instanceof RubyArray) {
        Schema s = rubyArgToSchema(arg);
        Ruby runtime = context.getRuntime();
        return new RubySchema(runtime, runtime.getClass("Schema"), s);
    } else {
        throw new RuntimeException("Bad argument given to Schema.tuple");
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:20,代码来源:RubySchema.java

示例4: map

import org.jruby.Ruby; //导入方法依赖的package包/类
/**
 * This is a ruby method which takes an array of arguments and constructs a Map schema from them. The name
 * will be set automatically.
 *
 * @param context the context the method is being executed in
 * @param self    the RubyClass for the Class object this was invoked on
 * @param arg     a list of arguments to instantiate the new RubySchema
 * @return        the new RubySchema
 */
@JRubyMethod(meta = true, name = {"m", "map"})
public static RubySchema map(ThreadContext context, IRubyObject self, IRubyObject arg) {
    Schema s = tuple(context, self, arg).getInternalSchema();
    Ruby runtime = context.getRuntime();
    try {
        return new RubySchema(runtime, runtime.getClass("Schema"), new Schema(new Schema.FieldSchema("map_0", s.getField(0).schema, DataType.MAP)));
    } catch (FrontendException e) {
        throw new RuntimeException("Error making map", e);
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:20,代码来源:RubySchema.java

示例5: bag

import org.jruby.Ruby; //导入方法依赖的package包/类
/**
 * This is a ruby method which takes an array of arguments and constructs a Bag schema from them. The name
 * will be set automatically.
 *
 * @param context the context the method is being executed in
 * @param self    the RubyClass for the Class object this was invoked on
 * @param arg     a list of arguments to instantiate the new RubySchema
 * @return        the new RubySchema
 */
@JRubyMethod(meta = true, name = {"b", "bag"})
public static RubySchema bag(ThreadContext context, IRubyObject self, IRubyObject arg) {
    Schema s = tuple(context, self, arg).getInternalSchema();
    Ruby runtime = context.getRuntime();
    try {
        return new RubySchema(runtime, runtime.getClass("Schema"), new Schema(new Schema.FieldSchema("bag_0", s, DataType.BAG)));
    } catch (FrontendException e) {
        throw new RuntimeException("Error making map", e);
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:20,代码来源:RubySchema.java

示例6: get

import org.jruby.Ruby; //导入方法依赖的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()+ " )");
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:20,代码来源:RubySchema.java

示例7: find

import org.jruby.Ruby; //导入方法依赖的package包/类
/**
 * Given a field name this string will search the RubySchema for a FieldSchema
 * with that name and return it encapsulated in a Schema.
 *
 * @param context the context the method is being executed in
 * @param arg     a RubyString serving as an alias to look
 *                for in the Schema
 * @return        the found RubySchema
 */
@JRubyMethod
public RubySchema find(ThreadContext context, IRubyObject arg) {
    if (arg instanceof RubyString) {
        Ruby runtime = context.getRuntime();
        return new RubySchema(runtime, runtime.getClass("Schema"), RubySchema.find(internalSchema, arg.toString()), false);
    } else {
        throw new RuntimeException("Invalid arguement passed to find: " + arg);
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:19,代码来源:RubySchema.java

示例8: clone

import org.jruby.Ruby; //导入方法依赖的package包/类
/**
 * This method returns a copy of the encapsulated DataBag.
 *
 * @param context the context the method is being executed in
 * @return        the copied RubyDataBag
 */
//TODO see if a deepcopy is necessary as well (and consider adding to DataBag and Tuple)
@JRubyMethod
public RubyDataBag clone(ThreadContext context) {
    DataBag b = mBagFactory.newDefaultBag();
    for (Tuple t : this)
        b.add(t);
    Ruby runtime = context.getRuntime();
    return new RubyDataBag(runtime, runtime.getClass("DataBag"), b);
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:16,代码来源:RubyDataBag.java

示例9: clone

import org.jruby.Ruby; //导入方法依赖的package包/类
/**
 * @param context the context the method is being executed in
 * @return        a RubySchema copy of the Schema
 */
@JRubyMethod
public RubySchema clone(ThreadContext context) {
    Ruby runtime = context.getRuntime();
    return new RubySchema(runtime, runtime.getClass("Schema"), internalSchema);
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:10,代码来源:RubySchema.java

示例10: plus

import org.jruby.Ruby; //导入方法依赖的package包/类
/**
 * This method accepts as an argument anything that could be passed to set (ie a
 * RubyDataByteArray, RubyString, or byte array). It then adds those values together.
 *
 * @param context the context the method is being executed in
 * @param arg     any argument that can validly initialize a RubyDataByteArray
 * @return        a <u>new</u> RubyDataByteArray that is the concatentation of
 *                the encapsulated DataByteArray and arg
 */
@JRubyMethod(name = "+")
public IRubyObject plus(ThreadContext context, IRubyObject arg) {
    Ruby runtime = context.getRuntime();
    RubyDataByteArray toAdd = new RubyDataByteArray(runtime, runtime.getClass("DataByteArray")).initialize(arg);
    return new RubyDataByteArray(runtime, runtime.getClass("DataByteArray"), internalDBA, toAdd.getDBA());
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:16,代码来源:RubyDataByteArray.java

示例11: pigToRuby

import org.jruby.Ruby; //导入方法依赖的package包/类
/**
 * A type specific conversion routine.
 *
 * @param ruby   the Ruby runtime to create objects in
 * @param object object to convert
 * @return       analogous Ruby type
 */
public static RubyDataBag pigToRuby(Ruby ruby, DataBag object) {
    return new RubyDataBag(ruby, ruby.getClass("DataBag"), object);
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:11,代码来源:PigJrubyLibrary.java

示例12: pigToRuby

import org.jruby.Ruby; //导入方法依赖的package包/类
/**
 * A type specific conversion routine.
 *
 * @param ruby   the Ruby runtime to create objects in
 * @param object object to convert
 * @return       analogous Ruby type
 */
public static RubySchema pigToRuby(Ruby ruby, Schema object) {
    return new RubySchema(ruby, ruby.getClass("Schema"), object);
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:11,代码来源:PigJrubyLibrary.java

示例13: makeNullAliasRubySchema

import org.jruby.Ruby; //导入方法依赖的package包/类
/**
 * This is a helper method to generate a RubySchema of the given type without an alias.
 *
 * @param context the context the method is being executed in
 * @param type    the DataType.PIGTYPE value to make the Schema from
 * @return        a RubySchema object encapsulated a Schema of the specified type
 */
private static RubySchema makeNullAliasRubySchema(ThreadContext context, byte type) {
   Ruby runtime = context.getRuntime();
   return new RubySchema(runtime, runtime.getClass("Schema"), new Schema(new Schema.FieldSchema(null, type)));
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:12,代码来源:RubySchema.java


注:本文中的org.jruby.Ruby.getClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。