Module: EndlessRuby

Extended by:
EndlessRuby
Included in:
EndlessRuby, Main, Main
Defined in:
lib/endlessruby.rb

Overview

EndlessRubyはRubyをendを取り除いて書けます。

erファイルをrequire require 'homuhomu.er' | require 'homuhomu'

erファイルを実行 $ path/to/endlessruby.rb homuhomu.er

erファイルをコンパイル $ path/to/endlessruby.rb -c src/homuhomu.er -o lib

=> src/homuhomu.er をコンパイルして lib/homuhomu.rb を書き出します。

-o が省略された場合はカレントディレクトリに書き出します。

Example:

class EndlessRubyWorld

def self.hello!
  puts "hello!"


[-2, -1, 0, 1, 2].reject do |x|
x < 0
end.each do |n|
puts n

Defined Under Namespace

Modules: Main

Constant Summary collapse

VERSION =

EndlessRuby のバージョンです

"0.1.0"

Instance Method Summary collapse

Instance Method Details

#endless_ruby_to_pure_ruby(options) ⇒ Object Also known as: to_pure_ruby, ER2PR, ER2RB

EndlessRubyの構文をピュアなRubyの構文に変換します。
options: オプションを表すHashまたはto_hashを実装したオブジェクト、構文を読み出すIOまたはto_ioを実装したオブジェクト、EndlessRubyの構文を表すStringまたはto_strを実装したオブジェクト、またはファイルのパス
optionsが文字列ならばそれをピュアなRubyの構文にします。それがIOならばIOから読み出してそれをピュアなRubyの構文にします。
ファイルのパスならばそのファイルかあ読み込みます それがHashならばそれはオプションです。それぞれHashを指定します。
options: { in: { io: optionsにIOを指定した場合と同じです any: それが存在するファイルのパスを表す文字列ならばそのファイルから読み出します。この場合のanyはoptionsにそのような文字列を指定するのと同じ意味です。 そうでない文字列ならばそれ自体をEndlessRubyの構文として読み出します。この場合のanyはoptionsに文字列を指定するのと同じ意味です。 それがIOならばそのIOから読み出します。この場合のany はin.ioを直接指定するのと同じです。 } out: { io: このIOに結果を書き出します。 any: ファイルのパスかIOです。ファイルのパスならばそのファイルに書き出します。IOならばそのIOに書き出します。 } decompile: trueならばコンパイルではなくてでコンパイルします。 }

opts[:io] には書き出すioを指定します。
from a file on disk:
EndlessRuby.ER2RB("filename.er")
from string that is source code:
EndlessRuby.ER2RB(<<DEFINE) # endlessruby syntax DEFINE
from IO:
file = open 'filename.er' EndlessRuby.ER2RB(file)

appoint input file and output file: ER2PR({ :in => { :any => 'filename.er' }, :out => { :any => 'filename.rb' } }) ER2PR({ :in => { :io => in_io }, :out => { :io => out_io } })



85
86
87
# File 'lib/endlessruby.rb', line 85

def endless_ruby_to_pure_ruby options
  converting_helper options
end

#ereval(src, binding = TOPLEVEL_BINDING, filename = __FILE__, lineno = 1) ⇒ Object

文字列をEndlessRubyの構文として実行します。引数の意味はKernel#evalと同じです



46
47
48
# File 'lib/endlessruby.rb', line 46

def ereval(src, binding=TOPLEVEL_BINDING, filename=__FILE__, lineno=1)
  eval(ER2PR(src), binding, filename, lineno)
end

#pure_ruby_to_endless_ruby(options) ⇒ Object Also known as: RB2ER, PR2ER

Rubyの構文をEndlessRubyの構文に変換します。optionsはendlessruby_to_pure_rubyと同じです。



94
95
96
97
98
# File 'lib/endlessruby.rb', line 94

def pure_ruby_to_endless_ruby options
  options = merge_options options
  options[:decompile] = true
  converting_helper options
end