如何在课堂上高效学习Ruby编程语言?
- 内容介绍
- 文章标签
- 相关推荐
本文共计93个文字,预计阅读时间需要1分钟。
pythonclass X: def __init__(self, @name=Bob): end
puts X.new
class X def initialize @name = "Bob" end blah blah end puts X.new # I want this to print X:Bob puts [X.new, X.new] # I want this to print [X:Bob, X:Bob] 覆盖类的to_s方法:
class X def initialize @name = "Bob" end def to_s "X:#{@name}" end end puts X.new # prints X:Bob puts [X.new, X.new].to_s # prints [X:Bob, X:Bob]
本文共计93个文字,预计阅读时间需要1分钟。
pythonclass X: def __init__(self, @name=Bob): end
puts X.new
class X def initialize @name = "Bob" end blah blah end puts X.new # I want this to print X:Bob puts [X.new, X.new] # I want this to print [X:Bob, X:Bob] 覆盖类的to_s方法:
class X def initialize @name = "Bob" end def to_s "X:#{@name}" end end puts X.new # prints X:Bob puts [X.new, X.new].to_s # prints [X:Bob, X:Bob]

