End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
OpenStruct#[]
ostruct[name] → object
lib/ostruct.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/ostruct.rb, line 291
def [](name)
@table[name.to_sym]
end
Returns the value of an attribute, or nil if there is no such attribute.
Example
require "ostruct" person = OpenStruct.new("name" => "John Smith", "age" => 70) person[:age] # => 70, same as person.age