I am trying to do a chaining method for the following two methods. After running this code, I kept getting the following output:
#
This fellow (tjackiw.tumblr.com) uses this as an interview question and gives a very clean walkthough of how & why the correct answer is similar to the following:
class Interpreter
def initialize(&block)
instance_eval(&block)
end
def at(time)
@time = time
self
end
def when(date)
@date = date
self
end
def we(*people)
@people = people
self
end
def going(where)
@where = where
self
end
def output
[@people.join(' and '), "are going", @where, @date, "at", @time].join(' ')
end
end