Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

OpenStruct#[]

ostruct[name] → object

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
See also #[]= #== .new #as_json also in 3.3 · 3.2 · 3.1 · 3.0