Class: ConcernedInheritance::Delegator

Inherits:
BasicObject
Defined in:
lib/concerned_inheritance/delegator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(baseclass, subclass, callback) ⇒ Delegator

Returns a new instance of Delegator.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/concerned_inheritance/delegator.rb', line 5

def initialize(baseclass, subclass, callback)
  @baseclass = baseclass
  @subclass  = subclass
  if !callback.is_a?(::Proc)
    raise ::ArgumentError, "#{callback} must be a proc"
  elsif (-1..0).cover?(callback.arity)
    instance_eval(&callback)
  else
    raise ::ArgumentError, "#{callback} must have an arity of 0, got #{callback.arity}"
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



17
18
19
# File 'lib/concerned_inheritance/delegator.rb', line 17

def method_missing(m, *args, &block)
  subclass.send m, *args, &block
end

Instance Attribute Details

#baseclassObject (readonly)

Returns the value of attribute baseclass.



3
4
5
# File 'lib/concerned_inheritance/delegator.rb', line 3

def baseclass
  @baseclass
end

#subclassObject (readonly)

Returns the value of attribute subclass.



3
4
5
# File 'lib/concerned_inheritance/delegator.rb', line 3

def subclass
  @subclass
end