Module: EacRubyUtils::Contextualizable

Included in:
EacRubyUtils::Console::DocoptRunner
Defined in:
lib/eac_ruby_utils/contextualizable.rb

Overview

Provides the method context which search and call a method in self and ancestor objects.

Instance Method Summary collapse

Instance Method Details

#context(method) ⇒ Object


6
7
8
9
10
11
12
13
14
# File 'lib/eac_ruby_utils/contextualizable.rb', line 6

def context(method)
  current = self
  while current
    return current.send(method) if current.respond_to?(method)

    current = current.respond_to?(:parent) ? current.parent : nil
  end
  raise "Context method \"#{method}\" not found for #{self.class}"
end