TryRubyネタで、私がふと疑問に思ったところ。
class Blurb
def content
@content
end
def content=(x)
@content = x
end
def time
@time
end
def time=(x)
@time = x
end
def mood
@mood
end
def mood=(x)
@mood = x
end
end
blurb1 = Blurb.new
p blurb1.content = "Today Mount Hood Was Stolen!"
p blurb1.time = Time.now
p blurb1.mood = :fine
この中の
p blurb1.mood = :fine
この部分に注目。
( ^∀^)❓"fine"でも同じじゃないの?
という疑問。
結果も
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
"Today Mount Hood Was Stolen!"
2023-04-28 11:16:04.284578 +0900
fine
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
とシンボルだろうが""だろうが結果は同じ。
しかし、若干違うらしい。
mood(気分)メソッドの中には、fineのほかsickやgoodなどの決まった言葉が入ると予想される。
曜日などに関してもそう。
上記のような場合にはシンボルを使う。
そうではない時は””を使うらしい。
結果は同じだけども。