既存クラスを変更する

JUnit と連携してうまいこと出来ないかなと思ったんだけど、直接呼び出す時以外はメソッドの変更できないのかねぇ・・・。かなり期待したんだが。

require 'java'

include_class 'test.Test'
include_class 'test.Test2'

test = Test.new
test.say #=> say
         #=> say2

test2 = Test2.new
test2.say #=> say2

class Test2
  def say
    puts "changed"
  end
end
test.say #=> say
         #=> say2

test = Test.new
test.say #=> say
         #=> say2

test2 = Test2.new
test2.say #=> changed