Sha256: a663de4fdfccfea5fd01f0f2ff6801a5d2be6ffadfbd95575dfcf63c9c696450

Contents?: true

Size: 1.35 KB

Versions: 17

Compression:

Stored size: 1.35 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
```

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

17 entries across 17 versions & 1 rubygems

Version Path
lite-ruby-1.1.9 docs/OPEN_STRUCT.md
lite-ruby-1.1.8 docs/OPEN_STRUCT.md
lite-ruby-1.1.7 docs/OPEN_STRUCT.md
lite-ruby-1.1.6 docs/OPEN_STRUCT.md
lite-ruby-1.1.5 docs/OPEN_STRUCT.md
lite-ruby-1.1.4 docs/OPEN_STRUCT.md
lite-ruby-1.1.3 docs/OPEN_STRUCT.md
lite-ruby-1.1.2 docs/OPEN_STRUCT.md
lite-ruby-1.1.1 docs/OPEN_STRUCT.md
lite-ruby-1.1.0 docs/OPEN_STRUCT.md
lite-ruby-1.0.31 docs/OPEN_STRUCT.md
lite-ruby-1.0.30 docs/OPEN_STRUCT.md
lite-ruby-1.0.29 docs/OPEN_STRUCT.md
lite-ruby-1.0.28 docs/OPEN_STRUCT.md
lite-ruby-1.0.27 docs/OPEN_STRUCT.md
lite-ruby-1.0.26 docs/OPEN_STRUCT.md
lite-ruby-1.0.25 docs/OPEN_STRUCT.md