RE: Trying to understand the difference between similaritera


#1

No I have tried that. It gives me just this output #


#2

removed_email_address@domain.invalid wrote:

No I have tried that. It gives me just this output #

That’s because the <%= %> construct outputs the return value of the
expression inside it. The .each method actually returns the object it’s
called on - which in this case would be @student.addresses, which isn’t
a string… Try:

<%= @student.addresses.inject{|s, address| s + "Address: #{address.addr1}
"} %>

#3

Alex Y. wrote:

removed_email_address@domain.invalid wrote:

No I have tried that. It gives me just this output #
That’s because the <%= %> construct outputs the return value of the
expression inside it. The .each method actually returns the object it’s
called on - which in this case would be @student.addresses, which isn’t
a string… Try:

<%= @student.addresses.inject{|s, address| s + "Address: #{address.addr1}
"} %>

Oops… That should probably be

<%= @student.addresses.inject(''){|s, address| s + "Address: #{address.addr1}
"} %>