Module: Delegated

Overview

Delegates all missing methods to object specified by #delegate method.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

:nodoc:



6
7
8
9
10
11
12
# File 'lib/mustang/support/delegated.rb', line 6

def method_missing(meth, *args, &block) # :nodoc:
  if (old_respond_to?(:delegate) && delegate.respond_to?(meth))
    delegate.send(meth, *args, &block)
  else
    old_method_missing(meth, *args, &block)
  end
end

Instance Method Details

#old_method_missingObject



3
# File 'lib/mustang/support/delegated.rb', line 3

alias_method :old_method_missing, :method_missing

#old_respond_to?Object



4
# File 'lib/mustang/support/delegated.rb', line 4

alias_method :old_respond_to?, :respond_to?

#respond_to?(meth) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'lib/mustang/support/delegated.rb', line 14

def respond_to?(meth) # :nodoc:
  if (old_respond_to?(:delegate))
    delegate.respond_to?(meth) or old_respond_to?(meth)
  else
    old_respond_to?(meth)
  end
end

#to_sObject

:nodoc:



22
23
24
# File 'lib/mustang/support/delegated.rb', line 22

def to_s # :nodoc:
  delegate.to_s
end