literal icon indicating copy to clipboard operation
literal copied to clipboard

[Idea] Optional raise on shadow

Open stevegeek opened this issue 1 year ago • 1 comments

A thought: how about adding an optional (as in configuration) raise if a prop reader/writer shadows an existing instance method on definition? Eg

class TestPropsRaiseWhenShadowing

 def thingy
    @stuff
  end
  def thingy=(stuff)
    @stuff = stuff
  end
  prop :thingy, Integer # Boom, raises as reader defined
  prop :thingy, Integer, reader: false, writer: :public # Boom, raises as writer
  prop :thingy, Integer, reader: false, writer: false, # no raise
end

Obviously shadowing is always a possibility but thinking about when literal properties are used in library code where the end-user dev must inherit from some base and then add props, we can offer guard against accidentally shadowing base methods?

stevegeek avatar Sep 07 '24 06:09 stevegeek

I think it makes sense to raise on shadow when the shadow is owned by the same class, but a really valid use of shadowing is to override a property from a super class.

joeldrapper avatar Oct 01 '24 11:10 joeldrapper

I’d be up for looking at a PR, but I’m going to close this issue as I don’t think it’s something we need to do and issues to me represent TODOs.

joeldrapper avatar Oct 22 '24 11:10 joeldrapper