class NumberBox attr_reader :num def initialize #在创建实例时被自动调用 @num = 0 end def plus(v) @num += v return self end def minus(v) @num -= v return self end end b = NumberBox.new b.plus(5).minus(4).plus(3) p b.num #=> 0 + 5 - 4 + 3
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |