19. 10.times do |n|
puts "No. #{n}"
end
コンパイルされた命令列を
C++で書かれた
VMが評価していきます
!RBIX
1933235666460458080
22
M
1
n
n
x
E
8
US-ASCII
10
__script__
i
10
4
10
63
0
57
1
0
21
2
17
I
2
I
0
I
0
-------snip------
hoge.rb
hoge.rbc
3行 158行
22. "Rubinius doesn't compile Ruby down native code, instead
it uses a JIT to compile certain blocks of code, but only
whenever possible (or deemed necessary based on the call
amounts)."
"RubiniusはRubyを機械語にコンパイルせずに、代わり
に、いくつかのブロックを可能なときだけ(あるいはそのブ
ロックの呼び出し回数に応じた必要性を判断して)、JITコンパイ
ルを行う"
誤解しがちなこと
(僕が誤解していたこと)
https://github.com/rubinius/rubinius/issues/3165
27. Rubyで
書かれているので
さくっと
「try!」実装する
なんてことも
できました!
class Object
----snip----
def try!(*a, &b)
if a.empty? && block_given?
if b.arity.zero?
instance_eval(&b)
else
yield self
end
else
public_send(*a, &b)
end
end
end kernel/alpha.rb
class NilClass
----snip----
def try!(*args)
nil
end
end kernel/nil.rb
% cat try_length.rb
p 'hoge'.try!(:length)
p nil.try!(:length)
% ./bin/rbx try_length.rb
4
nil
「kernel/」にRubyのメソッドの定義
が書かれているので、Objectクラスと
nilクラスにtry!を定義してコンパイル