repeat.rb

来自「ruby 例子程序(适合初学者) 在unix/linux上测试成功」· RB 代码 · 共 33 行

RB
33
字号
#!/usr/local/rubyclass Repeat	@@total=0	def initialize(string, times)		@string = string		@times = times	end	def repeat		@@total +=@times		return @string * @times	end	def total		"total times, so far:" + @@total.to_s	endenddata = Repeat.new("ack", 8)ditto = Repeat.new("again! ", 5)ditty = Repeat.new("nill, ltt, dd. ", 2)puts data.repeatputs data.totalputs ditto.repeatputs ditto.totalputs ditty.repeatputs ditty.total

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?