Sha256: e70eb6e61fd0aca950dc8fa5c44b6da9a01663d483684a40828025ba8a105f2f

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

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
```

`attributes`
------
Returns the key values as a hash 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'
```

`to_hash` aka `to_h`
------
Returns the key values as a hash of the assigned struct.

```ruby
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.

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lite-ruby-1.1.15 docs/OPEN_STRUCT.md
lite-ruby-1.1.14 docs/OPEN_STRUCT.md
lite-ruby-1.1.13 docs/OPEN_STRUCT.md
lite-ruby-1.1.12 docs/OPEN_STRUCT.md
lite-ruby-1.1.11 docs/OPEN_STRUCT.md
lite-ruby-1.1.10 docs/OPEN_STRUCT.md