Module: Dommy::Bridge::Methods::ClassMethods
- Defined in:
- lib/dommy/bridge/methods.rb
Instance Method Summary collapse
-
#inherited(subclass) ⇒ Object
‘extend` is per-singleton, so a subclass of an includer would not inherit `js_methods`.
- #js_methods(names) ⇒ Object
Instance Method Details
#inherited(subclass) ⇒ Object
‘extend` is per-singleton, so a subclass of an includer would not inherit `js_methods`. Re-extend each subclass as it is defined.
31 32 33 34 |
# File 'lib/dommy/bridge/methods.rb', line 31 def inherited(subclass) super subclass.extend(ClassMethods) end |
#js_methods(names) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dommy/bridge/methods.rb', line 36 def js_methods(names) own = names.map(&:to_s).freeze const_set(:JS_METHOD_NAMES, own) unless const_defined?(:JS_METHOD_NAMES, false) # Capture the ancestor's __js_method_names__ as a real method (if any) # at definition time. We can't use `super` here: classes like # StyleDeclaration define `method_missing`, so `super` would fall # through to it and return a CSS-property String instead of raising. parent = if superclass.method_defined?(:__js_method_names__) superclass.instance_method(:__js_method_names__) end define_method(:__js_method_names__) do base = parent ? parent.bind(self).call : [] (base + own).uniq.freeze end end |