Actions
Feature #4862
closedStruct#to_hash
Feature #4862:
Struct#to_hash
Description
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
Actions