Looping through an array while adding the data to a string and finally returning it, a faster way?

Posted by Hadi on Stack Overflow See other posts from Stack Overflow or by Hadi
Published on 2010-05-27T09:57:17Z Indexed on 2010/05/27 10:01 UTC
Read the original article Hit count: 157

Filed under:
|

Getting the customer's to_s method by looping through

Is there a Ruby idiom to write the code in 1 line (or shorter than 3 lines of code)?

def method string = "" @customers.each { |customer| string += customer.to_s + "\n" } string end

© Stack Overflow or respective owner

Related posts about ruby

Related posts about string