Module: Aldous::Service::Result::Base::PredicateMethodsForInheritance

Included in:
Aldous::Service::Result::Base
Defined in:
lib/aldous/service/result/base/predicate_methods_for_inheritance.rb

Instance Method Summary collapse

Instance Method Details

#inherited(child) ⇒ Object

For every child class, create a predicate method on the base named after the child that returns false and override the same predicate method on the child to return true. So if the child class is called Failure then we’ll have a predicate method called failure? which will return false on the base class and true on the actual child class.



13
14
15
16
17
18
19
# File 'lib/aldous/service/result/base/predicate_methods_for_inheritance.rb', line 13

def inherited(child)
  return if child.name == nil # unnamed class
  child_class_name_as_predicate = "#{underscore(child.name.split("::").last)}?"

  add_predicate_method_to_class(Aldous::Service::Result::Base, child_class_name_as_predicate, false)
  add_predicate_method_to_class(child, child_class_name_as_predicate, true)
end