Sha256: 0e9773e82f29d7e341142c0e4638525d39d42d43e63f92dc6f40889cf1b2ba1a
Contents?: true
Size: 824 Bytes
Versions: 23
Compression:
Stored size: 824 Bytes
Contents
# OpenStruct `Initialize` Allows the initialization of an OpenStruct with a setter block. ```ruby OpenStruct.new(name: 'bob', age: 60) do |o| o.gender = :M end ``` `[]` ------ Access a value in the OpenStruct by key, like a Hash. ```ruby person = OpenStruct.new(name: 'bob', age: 60) person['name'] #=> 'bob' ``` `[]=` ------ Store a value in the OpenStruct by key, like a Hash. ```ruby person = OpenStruct.new(name: 'bob', age: 60) person['name'] = 'tim' ``` `attributes` ------ Returns the key values of the assigned struct. ```ruby person = OpenStruct.new(name: 'bob', age: 60) person.attributes #=> { name: 'bob', age: 60 } ``` `replace` ------ Replaces values provided within the hash. ```ruby person = OpenStruct.new(name: 'bob', age: 60) person.replace(name: 'tom', age: 28) preson.name #=> 'tom' ```
Version data entries
23 entries across 23 versions & 1 rubygems