- ruby 1.8.7
- MacOS 10.8.2
#!/bin/env ruby class Calcurator def initialize(a,b) @a=a @b=b end def add p @a+@b end def subRet return @a-@b end def addValue(c,d) p @a+@b+c+d end def addValueRet(c) return @a+@b+c end def addMethod(m) return @a+@b+method(m).call end end class CalcTest def exec calc=Calcurator.new(2,1) calc.method(:add).call p calc.method(:subRet).call calc.method(:addValue).call(3,4) p calc.method(:addValueRet).call(4) p calc.method(:addMethod).call(:subRet) end end if __FILE__ == $0 then CalcTest.new.exec end
結果
3 1 10 7 4