Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 924 Bytes

OPEN_STRUCT.md

File metadata and controls

44 lines (32 loc) · 924 Bytes

OpenStruct

attributes

Returns the key values as a hash of the assigned struct.

person = OpenStruct.new(name: 'bob', age: 60)

person.attributes #=> { name: 'bob', age: 60 }

replace

Replaces values provided within the hash.

person = OpenStruct.new(name: 'bob', age: 60)

person.replace(name: 'tom', age: 28)
preson.name #=> 'tom'

to_hash aka to_h

Returns the key values as a hash of the assigned struct.

person = OpenStruct.new(name: 'bob', age: 60)

person.to_hash               #=> { table: { name: 'bob', age: 60 } }
person.to_hash(table: false) #=> { name: 'bob', age: 60 }

to_json aka as_json

Returns the key values as Json of the assigned struct.

person = OpenStruct.new(name: 'bob', age: 60)

person.to_json               #=> { table: { name: 'bob', age: 60 } }
person.to_json(table: false) #=> { name: 'bob', age: 60 }