Struct to Hash - 09 Jan 2013

I’ve been using Structs a lot lately, and recently needed to convert a Struct to a Hash. It’s a very simple process, and something that I’m sure I’ll use often.

Article = :title, :text

essay = 'Poem', 'Roses are Red'
# #<struct Article title="Poem", text="Roses are Red">

# {:title=>"Poem", :text=>"Roses are Red"}

Another cool thing I picked up was how to use map with indexes. {
  |article, index| article.title = title_array[index]