Class: ExplicitDelegator

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/explicit_delegator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ ExplicitDelegator

Returns a new instance of ExplicitDelegator.



10
11
12
13
# File 'lib/explicit_delegator.rb', line 10

def initialize(obj)
  super(obj)
  ensure_defined
end

Class Method Details

.enforce_definitions(*methods) ⇒ Object



4
5
6
7
8
# File 'lib/explicit_delegator.rb', line 4

def self.enforce_definitions(*methods)
  define_method(:enforced_methods) do
    super() | methods
  end
end

Instance Method Details

#enforced_methodsObject



15
16
17
# File 'lib/explicit_delegator.rb', line 15

def enforced_methods
  []
end

#ensure_definedObject



19
20
21
22
23
24
25
# File 'lib/explicit_delegator.rb', line 19

def ensure_defined
  missing_methods = []
  enforced_methods.each do |method|
    missing_methods << method unless __getobj__.methods.include?(method)
  end
  raise "Methods required to use #{self.class}: #{missing_methods}" unless missing_methods.empty?
end