class Bike
attr_accessor :color, :gear_numbers, :style
def spin
puts " spins! Woosh!"
end
end
gw = Bike.new
gw.color = "white"
gw.gear_numbers = 11
gw.style = "compact"
puts "This bike is #{gw.color} and it has #{gw.gear_numbers} gears. Oh, and it has a #{gw.style} design. Did I mention that my bike #{gw.spin}?"
使用內部評級法,這是我所得到的: 「!自旋Woosh」爲什麼Ruby在字符串之前打印object.method?
**spins! Woosh!
This bike is white and it has 11 gears. Oh, and it
has a compact design. Did I mention that my bike ?**
爲什麼來之前的字符串,爲什麼不是IN的字符串?
「簡單的程序以非常可預測的方式工作。」 ...和副作用以複雜的方式工作,因此使用副作用的程序並不簡單。這個問題很好地證明了這一點,這再次說明爲什麼應該儘可能地避免副作用。 –