The operator *<<* is better to add info into a variable.
For example:

name = ""
name.object_id
=> 70341910843080

name << "Jhon "
name.object_id
=> 70341910843080

name << "Doe "
name.object_id
=> 70341910843080

Note that the object_id is always the same.
It's not create a new object.

*Now, let see this:*
name = ""
name.object_id
=> 703419105*94080*

name += "John"
name.object_id
=> 703419105*49640*

name += " Doe"
name.object_id
=> 703419105*14060*

Note that always a new object will be created. 

But if you wanna put a String with interpolation into a variable, how this:
flash[:success] = "Your payment has completed. Please contact #{@
order.seller.name}  (mobile: #{@order.seller.mobile_number}, email: 
#{@order.seller.email} )"

I'll do the same way that you, because I lost just a little performance, 
but my code would be cleaner.

Or you prefer:
flash[:success] = "Your payment has completed. Please contact "
flash[:success] << @order.seller.name
flash[:success] << "(mobile: "
flash[:success] << @order.seller.mobile_number
flash[:success] << ", email: "
flash[:success] << @order.seller.email
flash[:success] << ")"

flash[:success]

rsrs... Ruby is clean man. Your interpolation is the better way.
flash[:success] = "Your payment has completed. Please contact #{@
order.seller.name}  (mobile: #{@order.seller.mobile_number}, email: 
#{@order.seller.email} )"

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/3f775529-6b04-456d-8b94-fb1d5c0ff52d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to