End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
OpenStruct.new
new(hash=nil)
lib/ostruct.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/lib/ostruct.rb, line 126
def initialize(hash=nil)
if hash
update_to_values!(hash)
else
@table = {}
end
end
Creates a new OpenStruct object. By default, the resulting OpenStruct object will have no attributes.
The optional hash, if given, will generate attributes and values (can be a Hash, an OpenStruct or a Struct). For example:
Example
require "ostruct" hash = { "country" => "Australia", :capital => "Canberra" } data = OpenStruct.new(hash) data # => #<OpenStruct country="Australia", capital="Canberra">