class Dog def initialize(name) @name = name end def set_nickname(nickname) #set with ruby_I don't use hoge, but this time I'll give it a try for simplicity! @nickname = nickname end def print_nickname if !defined?(@nickname) puts('Not Set') return end puts(@nickname) end end
If it is nil when you refer to if @age, you don't know which of the following cases.
-Is it nil because it has never been defined? --Is it the result of assigning @nickname = nil once?
In such a case, you should use