I have confusion for using expression interpolation in method. Initially I thought I can pass any kind of expression like let's say name.capitalize
, but I can pass without expression interpolation too. Here is the two cases. Just execute below two methods on irb
, I have same result for both method. I am using Ruby 1.9.3
1.
def say_goodnight(name)
result = "Good night, " + name.capitalize
return result
end
puts say_goodnight('uncle')
2.
def say_goodnight(name)
result = "Good night, #{name.capitalize}"
return result
end
puts say_goodnight('uncle')
Both way it will produce output like
Good night, Uncle
So my question is When Should I use expression interpolation in Ruby? and When Should I use parameter in Ruby?