Or since only keys are needed, use each_key iterator.

Also, I think ri should say that the "method" each "returns" the same Hash
on which you called the method.

-Kedar

On Tue, Feb 15, 2011 at 8:57 AM, Colin Law <clan...@googlemail.com> wrote:

> On 15 February 2011 16:46, Paul Bergstrom <li...@ruby-forum.com> wrote:
> > Why does this output the same hash again (like hash.inspect) and not
> > each key as I want?
> >
> > @myhash.each { |k,v| "<li>" + k + "</li>" }
>
> Because it is showing the return value of the method each, not what
> you are doing in the block.  You need to build up a string in the
> block which is the concatenation of your li strings.
> Crudely, something like
> str = ""
> @myhash.each { |k,v| str += "<li>#{k}</li>" }
>
> Colin
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to