1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module JRuby
  class Commands
    class << self
      # Provide method aliases to scripts commonly found in ${jruby.home}/bin.
      if File.directory?(Config::CONFIG['bindir'])
        Dir[Config::CONFIG['bindir'] + '/*'].each do |f|
          if File.file?(f) && File.open(f) {|io| (io.readline rescue "") =~ /^#!.*ruby/}
            meth = File.basename(f)
            define_method meth do
              require 'jruby/extract'
              JRuby::Extract.new.extract
              load f
            end
          end
        end
      else
        # allow use of 'gem' and 'jirb' without prior extraction
        def gem
          require 'jruby/extract'
          JRuby::Extract.new.extract
          require 'rubygems'
          Gem.manage_gems
          Gem::GemRunner.new.run(ARGV)
        end

        def jirb
          require 'irb'
          IRB.start(__FILE__)
        end
      end