Re: Outputting a string from an array of objects

Michael Pavling
Thu, 24 Feb 2011 18:15:24 -0000

On 24 February 2011 17:07, Peter D Bethke
<peter.bethke-ee4meeAH724@public.gmane.org> wrote:
>  def get_company_branches
>   my_branches =  self.company.branches
>   my_list = my_branches.each { |x| puts x.branch_name }
>   return my_list
>  end

You might find that something like this is what you''re after:

  def get_company_branches
    self.company.branches.collect(&:branch_name).join(", ") if
self.company && self.company.branches
  end

Have a look at the methods available to Array and Enumerable in both
the Rails and Ruby apis.