Complete the code to create a new OpenStruct object.
require 'ostruct' obj = [1].new
OpenStruct is the class used to create dynamic objects in Ruby.
Complete the code to set a dynamic attribute 'name' to 'Alice'.
require 'ostruct' obj = OpenStruct.new obj.[1] = 'Alice'
The attribute 'name' is set dynamically on the OpenStruct object.
Complete the code to access a missing attribute that returns nil instead of raising an error.
require 'ostruct' obj = OpenStruct.new puts obj.[1]
Accessing a missing attribute like 'missing_attr' returns nil without error in OpenStruct.
Fill both blanks to create an OpenStruct with the 'age' attribute set to 30.
require 'ostruct' obj = OpenStruct.new([1] => [2])
Use a hash with symbol keys and values to initialize OpenStruct attributes.
Fill all three blanks to add a new attribute 'country' with value 'France' to an existing OpenStruct object.
require 'ostruct' obj = OpenStruct.new(city: 'Paris') obj.[1] = [2] puts obj.[3]
You assign the new attribute 'country' with value 'France' and then print it.