interactor icon indicating copy to clipboard operation
interactor copied to clipboard

Using display as property name on Context

Open lenart opened this issue 5 years ago • 1 comments

I stumbled across this issue during specs where I named a property on the Context object display. The results were surprising and, after some code reading, it turns out it has to do with the way OpenStruct lazy-loads/queries properties.

Sample class

class SampleInteractor
  include Interactor

  def call
    context.display = 'Foobar'
  end
end

Expected

SampleInteractor.call.display # => 'Foobar'

Actual

SampleInteractor.call.display # => #<Interactor::Context display="Foobar">nil

As mentioned this problem is in using OpenStruct where the same behavior can be observed and it's all because there is already Object#display defined on Object.

Maybe something worth adding to the docs as a caveat?

lenart avatar Mar 13 '20 18:03 lenart

Thanks for the report and sorry it's sat for so long.

Documentation is one option though I'm also considering changing how we handle Context and using a default implementation based on BasicObject which has a much smaller API surface area compared to Object. That would hopefully mean fewer naming collisions.

gaffneyc avatar Jan 02 '25 16:01 gaffneyc