- ruby 1.8.7
- MacOS 10.8.2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #!/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 |
結果
1 2 3 4 5 | 3 1 10 7 4 |