• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java RubyModule类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jruby.RubyModule的典型用法代码示例。如果您正苦于以下问题:Java RubyModule类的具体用法?Java RubyModule怎么用?Java RubyModule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: hookIntoRuntime

import org.jruby.RubyModule; //导入依赖的package包/类
/**
 * Hooks this <code>TextAreaReadline</code> instance into the runtime,
 * redefining the <code>Readline</code> module so that it uses this object.
 * This method does not redefine the standard input-output streams. If you
 * need that, use {@link #hookIntoRuntimeWithStreams(Ruby)}.
 *
 * @param runtime The runtime.
 * @see #hookIntoRuntimeWithStreams(Ruby)
 */
public void hookIntoRuntime(final Ruby runtime) {
    this.runtime = runtime;
    /* Hack in to replace usual readline with this */
    runtime.getLoadService().require("readline");
    RubyModule readlineM = runtime.fastGetModule("Readline");

    readlineM.defineModuleFunction("readline", new Callback() {
        public IRubyObject execute(IRubyObject recv, IRubyObject[] args,
                                   Block block) {
            String line = readLine(args[0].toString());
            if (line != null) {
                return RubyString.newUnicodeString(runtime, line);
            } else {
                return runtime.getNil();
            }
        }

        public Arity getArity() {
            return Arity.twoArguments();
        }
    });
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:32,代码来源:TextAreaReadline.java


示例2: instantiateClass

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

	// try to load the module
	RubyModule rubyModule = runtime.getModule(module);

	if (rubyModule != null)
	{
		// now try to load the class
		RubyClass rubyClass = rubyModule.getClass(name);

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

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


示例3: define

import org.jruby.RubyModule; //导入依赖的package包/类
/**
 * This method registers the class with the given runtime.
 *
 * @param runtime an instance of the Ruby runtime
 * @return        a RubyClass object with metadata about the registered class
 */
public static RubyClass define(Ruby runtime) {
    RubyClass result = runtime.defineClass("Schema",runtime.getObject(), ALLOCATOR);

    result.kindOf = new RubyModule.KindOf() {
        public boolean isKindOf(IRubyObject obj, RubyModule type) {
            return obj instanceof RubySchema;
        }
    };

    result.includeModule(runtime.getEnumerable());

    result.defineAnnotatedMethods(RubySchema.class);

    return result;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:22,代码来源:RubySchema.java


示例4: define

import org.jruby.RubyModule; //导入依赖的package包/类
/**
 * This method registers the class with the given runtime. It is not necessary to do this here,
 * but it is simpler to associate the methods necessary to register the class with the class
 * itself, so on the Library side it is possible to just specify "RubyDataBag.define(runtime)".
 *
 * @param runtime an instance of the Ruby runtime
 * @return        a RubyClass object with metadata about the registered class
 */
public static RubyClass define(Ruby runtime) {
    // This generates the class object associated with DataBag, and registers it with the
    // runtime. The RubyClass object has all the metadata associated with a Class itself.
    RubyClass result = runtime.defineClass("DataBag", runtime.getObject(), ALLOCATOR);

    // This registers a method which can be used to know whether a module is an
    // instance of the class.
    result.kindOf = new RubyModule.KindOf() {
        public boolean isKindOf(IRubyObject obj, RubyModule type) {
            return obj instanceof RubyDataBag;
        }
    };

    // This includes the Enumerable module that we specified.
    result.includeModule(runtime.getEnumerable());

    // This method actually reads the annotations we placed and registers
    // all of the methods.
    result.defineAnnotatedMethods(RubyDataBag.class);

    // This returns the RubyClass object with all the new metadata.
    return result;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:32,代码来源:RubyDataBag.java


示例5: init

import org.jruby.RubyModule; //导入依赖的package包/类
private void init(Ruby ruby) {
    RubyModule nokogiri = ruby.defineModule("Nokogiri");
    RubyModule xmlModule = nokogiri.defineModuleUnder("XML");
    RubyModule xmlSaxModule = xmlModule.defineModuleUnder("SAX");
    RubyModule htmlModule = nokogiri.defineModuleUnder("HTML");
    RubyModule htmlSaxModule = htmlModule.defineModuleUnder("SAX");
    RubyModule xsltModule = nokogiri.defineModuleUnder("XSLT");

    createJavaLibraryVersionConstants(ruby, nokogiri);
    createNokogiriModule(ruby, nokogiri);
    createSyntaxErrors(ruby, nokogiri, xmlModule);
    RubyClass xmlNode = createXmlModule(ruby, xmlModule);
    createHtmlModule(ruby, htmlModule);
    createDocuments(ruby, xmlModule, htmlModule, xmlNode);
    createSaxModule(ruby, xmlSaxModule, htmlSaxModule);
    createXsltModule(ruby, xsltModule);
    nokogiri.setInternalVariable("cache", populateNokogiriClassCahce(ruby));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:19,代码来源:NokogiriService.java


示例6: load

import org.jruby.RubyModule; //导入依赖的package包/类
public void load(Ruby runtime, boolean wrap) throws IOException {
    RubyModule jo = runtime.defineModule("Jo");
    final ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactory() {
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setDaemon(true);
            return t;
        }
    });
    jo.setInternalVariable("executor", executor);
    RubyClass joFuture = jo.defineClassUnder("Future", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
    RubyClass joChannel = jo.defineClassUnder("Channel", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
    
    jo.defineAnnotatedMethods(JoMethods.class);
    joFuture.defineAnnotatedMethods(JoFuture.class);
    joChannel.defineAnnotatedMethods(JoChannel.class);
    
    runtime.addFinalizer(new Finalizable() {
        public void finalize() {
            executor.shutdown();
        }
    });
}
 
开发者ID:headius,项目名称:jo,代码行数:24,代码来源:JoLibrary.java


示例7: setup

import org.jruby.RubyModule; //导入依赖的package包/类
public static void setup(Ruby runtime) {
    RubyModule bindex = runtime.defineModule("Bindex");
    bindex.defineAnnotatedMethods(BindexMethods.class);

    RubyClass exception = runtime.getException();
    exception.defineAnnotatedMethods(ExceptionExtensionMethods.class);

    IRubyObject verbose = runtime.getVerbose();
    try {
        runtime.setVerbose(runtime.getNil());
        runtime.addEventHook(new SetExceptionBindingsEventHook());
    } finally {
        runtime.setVerbose(verbose);
    }
}
 
开发者ID:gsamokovarov,项目名称:bindex,代码行数:16,代码来源:JRubyIntegration.java


示例8: load

import org.jruby.RubyModule; //导入依赖的package包/类
public void load(Ruby runtime, boolean wrap) {
    RubyModule persistent = runtime.getOrCreateModule("Persistent");
    RubyClass persistentVector = persistent.defineOrGetClassUnder("Vector", runtime.getObject());
    persistentVector.setAllocator(new ObjectAllocator() {
        @Override
        public IRubyObject allocate(Ruby ruby, RubyClass rubyClass) {
            return new PersistentVector(ruby, rubyClass);
        }
    });
    persistentVector.includeModule(runtime.getEnumerable());
    persistentVector.defineAnnotatedMethods(PersistentVector.class);
}
 
开发者ID:Who828,项目名称:persistent_data_structures,代码行数:13,代码来源:PersistentVectorLibrary.java


示例9: define

import org.jruby.RubyModule; //导入依赖的package包/类
/**
 * Registers the DataByteArray class with the Ruby runtime.
 *
 * @param runtime an instance of the Ruby runtime
 * @return a RubyClass object with metadata about the registered class
 */
public static RubyClass define(Ruby runtime) {
    RubyClass result = runtime.defineClass("DataByteArray", runtime.getObject(), ALLOCATOR);

    result.kindOf = new RubyModule.KindOf() {
        public boolean isKindOf(IRubyObject obj, RubyModule type) {
            return obj instanceof RubyDataByteArray;
        }
    };

    result.defineAnnotatedMethods(RubyDataByteArray.class);

    return result;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:20,代码来源:RubyDataByteArray.java


示例10: createRubyOneofBuilderContext

import org.jruby.RubyModule; //导入依赖的package包/类
public static void createRubyOneofBuilderContext(Ruby runtime) {
    RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
    RubyModule internal = protobuf.defineModuleUnder("Internal");
    RubyClass cRubyOneofBuidlerContext = internal.defineClassUnder("OneofBuilderContext", runtime.getObject(), new ObjectAllocator() {
        @Override
        public IRubyObject allocate(Ruby ruby, RubyClass rubyClass) {
            return new RubyOneofBuilderContext(ruby, rubyClass);
        }
    });
    cRubyOneofBuidlerContext.defineAnnotatedMethods(RubyOneofBuilderContext.class);
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:12,代码来源:RubyOneofBuilderContext.java


示例11: createRubyOneofDescriptor

import org.jruby.RubyModule; //导入依赖的package包/类
public static void createRubyOneofDescriptor(Ruby runtime) {
    RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
    RubyClass cRubyOneofDescriptor = protobuf.defineClassUnder("OneofDescriptor", runtime.getObject(), new ObjectAllocator() {
        @Override
        public IRubyObject allocate(Ruby ruby, RubyClass rubyClass) {
            return new RubyOneofDescriptor(ruby, rubyClass);
        }
    });
    cRubyOneofDescriptor.defineAnnotatedMethods(RubyOneofDescriptor.class);
    cRubyOneofDescriptor.includeModule(runtime.getEnumerable());
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:12,代码来源:RubyOneofDescriptor.java


示例12: buildModuleFromDescriptor

import org.jruby.RubyModule; //导入依赖的package包/类
private RubyModule buildModuleFromDescriptor(ThreadContext context) {
    Ruby runtime = context.runtime;
    Utils.checkNameAvailability(context, name.asJavaString());

    RubyModule enumModule = RubyModule.newModule(runtime);
    for (Descriptors.EnumValueDescriptor value : descriptor.getValues()) {
        enumModule.defineConstant(value.getName(), runtime.newFixnum(value.getNumber()));
    }

    enumModule.instance_variable_set(runtime.newString(Utils.DESCRIPTOR_INSTANCE_VAR), this);
    enumModule.defineAnnotatedMethods(RubyEnum.class);
    return enumModule;
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:14,代码来源:RubyEnumDescriptor.java


示例13: register

import org.jruby.RubyModule; //导入依赖的package包/类
public void register(final Class<? extends Converter> converterClass, String... backends) {
    RubyModule module = rubyRuntime.defineModule(getModuleName(converterClass));
    RubyClass clazz = module.defineClassUnder(
            converterClass.getSimpleName(),
            rubyRuntime.getObject(),
            new ConverterProxy.Allocator(converterClass));
    clazz.defineAnnotatedMethods(ConverterProxy.class);
    if (backends.length > 0) {
        this.asciidoctorModule.register_converter(clazz, backends);
    } else {
        this.asciidoctorModule.register_converter(clazz);
    }
}
 
开发者ID:asciidoctor,项目名称:asciidoctorj,代码行数:14,代码来源:JavaConverterRegistry.java


示例14: instantiate

import org.jruby.RubyModule; //导入依赖的package包/类
public static IRubyObject instantiate(final Ruby ruby, final String className, final Object[] parameters) {
    IRubyObject result = null;
    RubyModule rubyClass = ruby.getClassFromPath( className );

    if (rubyClass != null) {
        try {
            result = (IRubyObject) JavaEmbedUtils.invokeMethod( ruby, rubyClass, "new", parameters, IRubyObject.class );
        } catch (Exception e) {
            log.error("Unable to instantiate: " + className, e);
            throw e;
        }
    }

    return result;
}
 
开发者ID:projectodd,项目名称:wunderboss,代码行数:16,代码来源:RubyHelper.java


示例15: createHtmlModule

import org.jruby.RubyModule; //导入依赖的package包/类
private void createHtmlModule(Ruby ruby, RubyModule htmlModule) {
    RubyClass htmlElemDesc = htmlModule.defineClassUnder("ElementDescription", ruby.getObject(), HTML_ELEMENT_DESCRIPTION_ALLOCATOR);
    htmlElemDesc.defineAnnotatedMethods(HtmlElementDescription.class);
    
    RubyClass htmlEntityLookup = htmlModule.defineClassUnder("EntityLookup", ruby.getObject(), HTML_ENTITY_LOOKUP_ALLOCATOR);
    htmlEntityLookup.defineAnnotatedMethods(HtmlEntityLookup.class);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:8,代码来源:NokogiriService.java


示例16: createDocuments

import org.jruby.RubyModule; //导入依赖的package包/类
private void createDocuments(Ruby ruby, RubyModule xmlModule, RubyModule htmlModule, RubyClass node) {
    RubyClass xmlDocument = xmlModule.defineClassUnder("Document", node, XML_DOCUMENT_ALLOCATOR);
    xmlDocument.defineAnnotatedMethods(XmlDocument.class);
    
    //RubyModule htmlDoc = html.defineOrGetClassUnder("Document", document);
    RubyModule htmlDocument = htmlModule.defineClassUnder("Document", xmlDocument, HTML_DOCUMENT_ALLOCATOR);
    htmlDocument.defineAnnotatedMethods(HtmlDocument.class);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:9,代码来源:NokogiriService.java


示例17: createSaxModule

import org.jruby.RubyModule; //导入依赖的package包/类
private void createSaxModule(Ruby ruby, RubyModule xmlSaxModule, RubyModule htmlSaxModule) {
    RubyClass xmlSaxParserContext = xmlSaxModule.defineClassUnder("ParserContext", ruby.getObject(), XML_SAXPARSER_CONTEXT_ALLOCATOR);
    xmlSaxParserContext.defineAnnotatedMethods(XmlSaxParserContext.class);
    
    RubyClass xmlSaxPushParser = xmlSaxModule.defineClassUnder("PushParser", ruby.getObject(), XML_SAXPUSHPARSER_ALLOCATOR);
    xmlSaxPushParser.defineAnnotatedMethods(XmlSaxPushParser.class);
    
    RubyClass htmlSaxPushParser = htmlSaxModule.defineClassUnder("PushParser", ruby.getObject(), HTML_SAXPUSHPARSER_ALLOCATOR);
    htmlSaxPushParser.defineAnnotatedMethods(HtmlSaxPushParser.class);
    
    RubyClass htmlSaxParserContext = htmlSaxModule.defineClassUnder("ParserContext", xmlSaxParserContext, HTML_SAXPARSER_CONTEXT_ALLOCATOR);
    htmlSaxParserContext.defineAnnotatedMethods(HtmlSaxParserContext.class);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:14,代码来源:NokogiriService.java


示例18: getRackInputClass

import org.jruby.RubyModule; //导入依赖的package包/类
private static RubyClass getRackInputClass(Ruby runtime) {
  RubyModule module = runtime.getOrCreateModule("RackServlet");
  RubyClass klass = module.getClass("RackInput");
  if (klass == null) {
    klass = module.defineClassUnder("RackInput", runtime.getObject(), ALLOCATOR);
    klass.defineAnnotatedMethods(JRubyRackInput.class);
  }
  return klass;
}
 
开发者ID:square,项目名称:rack-servlet,代码行数:10,代码来源:JRubyRackInput.java


示例19: basicLoad

import org.jruby.RubyModule; //导入依赖的package包/类
@Override
public boolean basicLoad(Ruby ruby) throws IOException {
    final RubyModule module = ruby.defineModule("Collapstring");
    module.defineAnnotatedMethods(CollapstringService.class);
    return true;
}
 
开发者ID:airbnb,项目名称:collapstring,代码行数:7,代码来源:CollapstringService.java


示例20: getDescriptor

import org.jruby.RubyModule; //导入依赖的package包/类
@JRubyMethod(meta = true, name = "descriptor")
public static IRubyObject getDescriptor(ThreadContext context, IRubyObject recv) {
    return ((RubyModule) recv).getInstanceVariable(Utils.DESCRIPTOR_INSTANCE_VAR);
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:5,代码来源:RubyEnum.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Configuration类代码示例发布时间:2022-05-21
下一篇:
Java OWLReasonerFactory类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap