my solution is like
if (not (defined?(@results).nil?)) @results += "run" else @results = "run" end
but I believe that there is something simpler ...
I would probably do it like this:
@results = @results.to_s + "run"
This works because NilClass defines a #to_s method that returns a zero-length String, and because instance variables are automatically initialized to nil.
NilClass
#to_s
2.1m questions
2.1m answers
60 comments
57.0k users