class Yieldable::Mixin

Attributes

method_name[R]
once[R]
proc[RW]

Public Class Methods

new(method_name = :call, once: true) click to toggle source
Calls superclass method
# File lib/yieldable.rb, line 109
def initialize(method_name = :call, once: true)
  @method_name = method_name
  @once = once
  @proc = nil
  super()
end

Public Instance Methods

append_features(base) click to toggle source
Calls superclass method
# File lib/yieldable.rb, line 132
def append_features(base)
  return unless write_once_in_constant(base)
  base.include InstanceMethodsMixin
  super
end
extend_object(base) click to toggle source

Hook to invoke on `extend Yieldable`.

Calls superclass method
# File lib/yieldable.rb, line 118
def extend_object(base)
  return unless write_once_in_constant(base)
  base.extend(ToProcReader)         unless base.singleton_class.method_defined?(:to_proc)
  base.extend(Inheritance)          if base.singleton_class.method_defined?(@method_name)
  base.extend(WaitMethodDefinition) if wait_method_definition?
  super
end
prepend_features(base) click to toggle source
Calls superclass method
# File lib/yieldable.rb, line 126
def prepend_features(base)
  return unless write_once_in_constant(base)
  base.prepend InstanceMethodsMixin
  super
end

Private Instance Methods

wait_method_definition?() click to toggle source
# File lib/yieldable.rb, line 144
def wait_method_definition?
  @proc.nil? || !@once
end
write_once_in_constant(base) click to toggle source
# File lib/yieldable.rb, line 140
def write_once_in_constant(base)
  base.const_set(:YieldableMixin, self) unless base.const_defined?(:YieldableMixin)
end