module BBLib::Delegator
Public Class Methods
included(base)
click to toggle source
# File lib/bblib/core/mixins/delegator.rb, line 4 def self.included(base) base.extend(ClassMethods) base.send(:attr_ary, :instance_delegates) end
Public Instance Methods
delegates()
click to toggle source
# File lib/bblib/core/mixins/delegator.rb, line 9 def delegates (instance_delegates + self.class.delegates).uniq end
Protected Instance Methods
delegate_to(*mthds)
click to toggle source
# File lib/bblib/core/mixins/delegator.rb, line 45 def delegate_to(*mthds) mthds.flatten.each do |method| next if instance_delegates.include?(method) instance_delegates << method end true end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/bblib/core/mixins/delegator.rb, line 15 def method_missing(method, *args, &block) delegates.each do |delegate| case delegate when Symbol next unless respond_to?(delegate) && method(delegate).arity == 0 object = send(delegate) next unless object.respond_to?(method) return object.send(method, *args, &block) else next unless delegate.respond_to?(method) return delegate.send(method, *args, &block) end end super end
respond_to_missing?(method, include_private = false)
click to toggle source
Calls superclass method
# File lib/bblib/core/mixins/delegator.rb, line 31 def respond_to_missing?(method, include_private = false) return super if self.class.delegate_fast super || delegates.any? do |delegate| next if delegate == self # Protection from recursion case delegate when Symbol self.method(delegate)&.arity == 0 && send(delegate).respond_to?(method) else delegate.respond_to?(method) end end end