Closed afeld closed 7 years ago
I think it's not supported, but it should be a feature request. I believe subclassing should make it into two separate enums with their own values.
This is not supported. What should the default behavior be for sub classes? Based on your comment above I understand that a class of type S that inherits from T should have the same enums defined in T correct?
class T
define :RED, 'red'
define :GREEN, 'green'
end
class S < T
define :BLACK, 'black'
end
S::RED # => 'red'
S::GREEN # => 'green'
S::BLACK # => 'black'
Yes @laertispappas. I think this is correct, and in your exaple T::BLACK
should obviously not be a thing.
Great. Any propose method on how to implement this? I'm about to make a PR to support this if it's OK and no one is working on this.
I have faced the same issue on a gem we maintain with the same behavior. We were "losing" the functionality on sub classes because the behavior was defined on self.included
method. In order to bypass this I'm thinking of implementing the self.inherited
method and provide all the functionality to subclasses. What do you think about it?
I think anything that works that doesn't break existing functionality works! ;)
:)
Implemented via https://github.com/dblock/ruby-enum/pull/13.
if it's supported: add some tests for it; if not: raise an error when trying to subclass, or when trying to call
.define
from the subclass