method

to_h

Importance_1
Ruby latest stable (v2_5_5) - 0 notes - Class: Struct
to_h() public

Returns a Hash containing the names and values for the struct’s members.

Customer = Struct.new(:name, :address, :zip)
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
joe.to_h[:address]   #=> "123 Maple, Anytown NC"
Show source
Register or log in to add new notes.