From: Hal Brodigan <postmodern.mod3@...>
Date: 2011-06-10T11:31:44+09:00
Subject: [ruby-core:36909] [Ruby 1.9 - Feature #4862][Open] Struct#to_hash


Issue #4862 has been reported by Hal Brodigan.

----------------------------------------
Feature #4862: Struct#to_hash
http://redmine.ruby-lang.org/issues/4862

Author: Hal Brodigan
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


Occasionally, it is necessary to convert a Struct to a Hash (especially when generating JSON from an Array of Structs). A Struct#to_hash method would be very useful in this situation.

    class Struct

      #
      # Returns the Hash representation of the members and values within the struct.
      #
      def to_hash
        new_hash = {}

        each_pair do |member,value|
          new_hash[member] = value
        end

        new_hash
      end

    end


-- 
http://redmine.ruby-lang.org