I am wondering if a class or any variable is chained to one or more methods? Which return value would it give? (
restaurants = 
restaurants << Restaurant.new.import_line(line.chomp)
The return value is always the last thing in the chain, no exceptions. The result is not necessarily the thing you'd expect, though, as the last thing in the chain might do some tricky stuff.
For example, just to be clear:
Restaurant.new.import_line do |line| line + '!' end
There's no obligation here for
import_line to return the result of that block, and it's often the case that it won't.
You can also have occasions where the thing you're chaining switches completely and catches you off guard so you have to be sure about the return values from each function in the chain you're calling.
"help!".gsub!(/!/, '?').length # => 5 "help?".gsub!(/!/, '?').length #! NoMethodError: undefined method `length' for nil:NilClass
In this case
gsub! returns the string if and only if a change was made, otherwise
nil, which means you can't chain it in that case.