Module: EndlessRuby::Main
- Extended by:
- EndlessRuby, Main
- Includes:
- EndlessRuby
- Included in:
- Main
- Defined in:
- lib/endlessruby/main.rb
Constant Summary
Constants included from EndlessRuby
Class Method Summary collapse
-
.main(argv) ⇒ Object
$ endlessruby.rb args とまったく同じ動作をします。argvはARGVと同じ形式でなければなりません。.
Instance Method Summary collapse
-
#compile(er, rb) ⇒ Object
er ファイルから読み込みそれをピュアなRubyにコンパイルしてrbに書き出します.
-
#decompile(rb, er) ⇒ Object
rbファイルを読み込みそれからすべてのendを取り除きます。.
-
#endlessruby(argv) ⇒ Object
EndlessRuby::Main.main と同じ動作をします。このモジュールをincludeした場合に使用します。.
Methods included from EndlessRuby
endless_ruby_to_pure_ruby, ereval, pure_ruby_to_endless_ruby
Class Method Details
.main(argv) ⇒ Object
$ endlessruby.rb args とまったく同じ動作をします。argvはARGVと同じ形式でなければなりません。
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/endlessruby/main.rb', line 26 def self.main argv if argv.first && File.exist?(argv.first) $PROGRAM_NAME = argv.shift open $PROGRAM_NAME do |file| EndlessRuby.ereval file.read, TOPLEVEL_BINDING, $PROGRAM_NAME end return true end require 'optparse' = { } parser = OptionParser.new do |opts| opts.version = EndlessRuby::VERSION opts.on '-o OUT', 'appoint output directory.' do |out| [:out] = out end opts.on '-c', '--compile', 'compile endlessruby source code to pure ruby' do |c| [:compile] = true end opts.on '-d', '--decompile', 'decompile pure ruby source code to endless ruby' do |d| [:decompile] = true end opts.on '-r', 'unimplemented' do |r| [:recursive] = true end end parser.parse! argv if [:compile] out = [:out] || '.' argv.each do |er| unless File.exist? er puts "no such file to load -- #{er}" next end if File.directory? er unless [:recursive] puts "Is a directory - #{er}" next end # Unimolementation next end rb = er if er =~ /^(.*)\.er$/ rb = $1 end rb = File.split(rb)[1] rb = File.join(out, "#{rb}.rb") compile er, rb end elsif [:decompile] out = [:out] || '.' argv.each do |rb| unless File.exist? rb puts "no such file to load -- #{rb}" next end if File.directory? rb unless [:recursive] puts "Is a directory - #{rb}" next end # Unimolementation next end er = rb if rb =~ /^(.*)\.rb$/ er = $1 end er = File.split(er)[1] er = File.join(out, "#{er}.er") decompile rb, er end end end |
Instance Method Details
#compile(er, rb) ⇒ Object
er ファイルから読み込みそれをピュアなRubyにコンパイルしてrbに書き出します
11 12 13 |
# File 'lib/endlessruby/main.rb', line 11 def compile er, rb ER2PR({ :in => { :any => er }, :out => { :any => rb } }) end |
#decompile(rb, er) ⇒ Object
rbファイルを読み込みそれからすべてのendを取り除きます。
16 17 18 |
# File 'lib/endlessruby/main.rb', line 16 def decompile rb, er PR2ER({ :in => { :any => rb }, :out => { :any => er } }) end |
#endlessruby(argv) ⇒ Object
EndlessRuby::Main.main と同じ動作をします。このモジュールをincludeした場合に使用します。
21 22 23 |
# File 'lib/endlessruby/main.rb', line 21 def endlessruby argv EndlessRuby::Main.main argv end |