I have the following code where I instantiate an object that returns an OpenStruct result.
require 'ostruct'
class TestModel
attr_accessor :result
def initializer
end
def result
OpenStruct.new(successful?: false)
end
def successful!
result.send('successful?', true)
end
end
I want the class to work so that I could modify any attributes of my result
on the fly.
test = TestModel.new
test.result
=> #<OpenStruct successful?=false>
test.result.successful!
=> #<OpenStruct successful?=true>
This syntax comes from the official OpenStruct page, and it works just on its own but not inside an instantiated class - https://ruby-doc.org/stdlib-2.5.3/libdoc/ostruct/rdoc/OpenStruct.html
result.send('successful?', true)
I've also tried to use lambda
but to no avail
def result
OpenStruct.new(successful?: false, :successful! => lamdba {self.uccessful? = true})
end
Any ideas? I really want to know how to do that.