Class OpenStruct
In: lib/extensions/ostruct.rb
Parent: Object

Methods

new  

External Aliases

initialize -> old_initialize

Public Class methods

Allows the initialization of an OpenStruct with a block:

  person = OpenStruct.new do |p|
    p.name    = 'John Smith'
    p.gender  = :M
    p.age     = 71
  end

You can still provide a hash for initialization purposes, and even combine the two approaches if you wish.

  person = OpenStruct.new(:name => 'John Smith', :age => 31) do |p|
    p.gender = :M
  end

[Source]

# File lib/extensions/ostruct.rb, line 35
    def initialize(*args) # :yield: self

      old_initialize(*args)
      yield self if block_given?
    end

[Validate]