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と同じ形式でなければなりません。
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 118 119 120 121 122 123 |
# File 'lib/endlessruby/main.rb', line 35 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.on '-o OUT' do |out| [:out] = out end opts.on '-c', '--compile' do |c| [:compile] = true end opts.on '-d', '--decompile' do |d| [:decompile] = true end opts.on '-r' 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 14 15 16 17 |
# File 'lib/endlessruby/main.rb', line 11 def compile er, rb open(er) do |erfile| open(rb, "w") do |rbfile| rbfile.write ER2PR(erfile.read) end end end |
#decompile(rb, er) ⇒ Object
rbファイルを読み込みそれからすべてのendを取り除きます。
20 21 22 23 24 25 26 |
# File 'lib/endlessruby/main.rb', line 20 def decompile rb, er open(rb) do |rbfile| open(er, "w") do |erfile| erfile.write PR2ER(rbfile.read) end end end |
#endlessruby(argv) ⇒ Object
EndlessRuby::Main.main と同じ動作をします。このモジュールをincludeした場合に使用します。
30 31 32 |
# File 'lib/endlessruby/main.rb', line 30 def endlessruby argv EndlessRuby::Main.main argv end |