Skip to content

Commit b2a29ed

Browse files
committed
Fix inherited hook in helper
1 parent b8aab59 commit b2a29ed

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## Unreleased
2+
- Fix issue with inherited hook in helper ([#33](https://github.com/avo-hq/class_variants/pull/33))
3+
14
## 1.1.0 (2025-01-20)
25
- Add support for merging ([#23](https://github.com/avo-hq/class_variants/pull/23))
36
- Add support for subclass inheritance in helper ([#24](https://github.com/avo-hq/class_variants/pull/24))

lib/class_variants/helper.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ def class_variants(...)
1111
def self.included(base)
1212
base.extend(ClassMethods)
1313
base.singleton_class.instance_variable_set(:@_class_variants_instance, ClassVariants::Instance.new)
14-
base.define_singleton_method(:inherited) do |subclass|
14+
15+
def base.inherited(subclass)
16+
super if defined?(super)
17+
1518
subclass.singleton_class.instance_variable_set(
16-
:@_class_variants_instance, base.singleton_class.instance_variable_get(:@_class_variants_instance).dup
19+
:@_class_variants_instance, singleton_class.instance_variable_get(:@_class_variants_instance).dup
1720
)
1821
end
1922
end

0 commit comments

Comments
 (0)