From: Charles Oliver Nutter Date: 2012-08-01T16:29:12+09:00 Subject: [ruby-core:46909] Re: (Half-baked DRAFT) new `require' framework On Tue, Jul 31, 2012 at 7:29 AM, SASADA Koichi wrote: > (Proposal-2) > However, Proposal-1 is too big and we have not-enough time to discuss > about it. I propose alternative feature: `require' contractible > primitives. Break down `require' process and add primitives which can > implement `customized require' in Ruby (or C level). > Using (Proposal-2), we can make gem which provides (Proposal-1). We can > try and discuss about good design of (Proposal-1). Yes! The lookup logic should be the first thing exposed to Ruby, and then options to "properly" load code is a secondary feature. > JRuby can require file from `.jar' (and .war file? sorry i'm not sure). JRuby can load from anything on Java's "classpath", which can include jar files, paths on the filesystem, or anything added to the JVM's classpath. We do very little to make classpath/classloader resources available; we just look there as a last resort. FWIW, this also includes network resources... system ~/projects/jruby $ ssh 192.168.0.200 "cat public_html/some_library.rb" headius@192.168.0.200's password: puts 'this is on the server!' system ~/projects/jruby $ jruby -rjava -e '$CLASSPATH << "http://192.168.0.200/~headius/"; load "some_library.rb"' this is on the server! We inherit this behavior from the JVM. > JRuby also extends file path like VFS (virtual file system). JRuby can > open a file in a .jar file like file system. > (JRuby GURU: Please complement this section!) We do have some support for URLs that include a .jar file as part of their structure, but it's still mostly a JVM thing. We add the ability to have jar files within jar files and still search them, but it's a minor classloader trick. Torquebox does (or did) use JBoss VFS to provide more extensive filesystem simulation within jars and classloader archives. FYI, jar files are just zip files. There's no reason MRI could not do the same thing. I have been trying to encourage this for years :( > === Rubinius > > Rubinius supports AOT compile (a ruby script to a compiled file). > (Rubinius GURU: Please complement it!) I should mention that JRuby supports precompiled Ruby code; we search for .class when .rb are searched and not found. .rb can be compiled to .class, and there's no significant functional difference other than being precompiled (and being nearly impossible to reverse-engineer unless you know JVM bytecode, JRuby internals, and Ruby logic). system ~/projects/jruby $ cat blah.rb puts 'hello from compiled code!' system ~/projects/jruby $ jrubyc blah.rb system ~/projects/jruby $ rm blah.rb system ~/projects/jruby $ jruby -e "load 'blah.rb'" hello from compiled code! system ~/projects/jruby $ file blah.class blah.class: compiled Java class data, version 51.0 system ~/projects/jruby $ javap blah Compiled from "blah.rb" public class blah extends org.jruby.ast.executable.AbstractScript { public blah(); public static org.jruby.runtime.builtin.IRubyObject __file__(blah, org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.builtin.IRubyObject[], org.jruby.runtime.Block); public org.jruby.runtime.builtin.IRubyObject __file__(org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.builtin.IRubyObject[], org.jruby.runtime.Block); public org.jruby.runtime.builtin.IRubyObject load(org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, boolean); public static void main(java.lang.String[]); } > === Java Jigsaw project > > (Java GURU: Help me to complement it!) Jigsaw is intended as a new module and namespace system for Java applications. I'm not sure the authors know exactly how it works, but you could get a general idea by studying the classloader system...and OSGi, a current, working implementation of namespaced modules for the JVM. JRuby users have used both Maven and OSGi for years to include JRuby in modularized systems and to control modularized systems from JRuby. > Make an `extensible require' framework for require(). > It's my draft (not implemented yet): > I will try to read this in depth soon! > == Usecase > > (snip... not described yet) RubyGems without RubyGems hacks? :) Arbitrary sourcing of code from archives, network, and more? All the cool stuff JRuby can do? :) - Charlie