Module: Wallaby::ModuleUtils

Defined in:
lib/utils/wallaby/module_utils.rb

Overview

Utils for module and class

Class Method Summary collapse

Class Method Details

.anonymous_class?(klass) ⇒ true, false

Check whether a class is anonymous or not

Parameters:

  • klass (Class)

Returns:

  • (true)

    if a class is anonymous

  • (false)

    otherwise



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

Parameters:

  • child (Class)

    child class

  • parent (Class)

    parent class

Raises:

  • (ArgumentError)

    if given class is not a child of the other 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

Parameters:

  • subject (Object)

Yields:

  • (subject)


34
35
36
# File 'lib/utils/wallaby/module_utils.rb', line 34

def yield_for(subject)
  block_given? ? yield(subject) : subject
end