Module: Wallaby::ModuleUtils
- Defined in:
- lib/utils/wallaby/module_utils.rb
Overview
Utils for module and class
Class Method Summary collapse
-
.anonymous_class?(klass) ⇒ true, false
Check whether a class is anonymous or not.
-
.inheritance_check(child, parent) ⇒ Object
Check if a child class inherits from parent class.
- .try_to(_subject, _method_id, *_args) ⇒ Object deprecated Deprecated.
-
.yield_for(subject) {|subject| ... } ⇒ Object
If block is given, run the block.
Class Method Details
.anonymous_class?(klass) ⇒ true, false
Check whether a class is anonymous or not
16 17 18 |
# File 'lib/utils/wallaby/module_utils.rb', line 16 def anonymous_class?(klass) klass.name.blank? || klass.to_s.start_with?('#<Class') end |
.inheritance_check(child, parent) ⇒ Object
Check if a child class inherits from parent class
24 25 26 27 28 29 |
# File 'lib/utils/wallaby/module_utils.rb', line 24 def inheritance_check(child, parent) return unless child && parent return if child < parent raise ::ArgumentError, Locale.t('errors.invalid.inheritance', klass: child, parent: parent) end |
.try_to(_subject, _method_id, *_args) ⇒ Object
Deprecated.
8 9 10 |
# File 'lib/utils/wallaby/module_utils.rb', line 8 def try_to(_subject, _method_id, *_args) Deprecator.alert method(__callee__), from: '0.3.0' end |
.yield_for(subject) {|subject| ... } ⇒ Object
If block is given, run the block. Otherwise, return subject
34 35 36 |
# File 'lib/utils/wallaby/module_utils.rb', line 34 def yield_for(subject) block_given? ? yield(subject) : subject end |