Skip to content

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

instance method

OpenStruct#[]=

ostruct[name] = obj → obj

Sets the value of an attribute.

Example
require "ostruct"
person = OpenStruct.new("name" => "John Smith", "age" => 70)
person[:age] = 42   # equivalent to person.age = 42
person.age          # => 42
See also #[] #as_json #== #delete_field also in 3.4 · 3.2 · 3.1 · 3.0