Class: Masamune::MethodLogger

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

Instance Method Summary collapse

Constructor Details

#initialize(target, *methods) ⇒ MethodLogger

Returns a new instance of MethodLogger.



26
27
28
29
30
# File 'lib/masamune/method_logger.rb', line 26

def initialize(target, *methods)
  super target
  @target = target
  @methods = methods
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



32
33
34
35
36
37
38
39
# File 'lib/masamune/method_logger.rb', line 32

def method_missing(method_name, *args, &block)
  @target.environment.console("#{method_name} with #{args.join(' ')}") if @methods.include?(method_name)
  if @target.respond_to?(method_name)
    @target.__send__(method_name, *args, &block)
  else
    super
  end
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/masamune/method_logger.rb', line 41

def respond_to_missing?(method_name, include_private = false)
  @target.respond_to?(method_name) || super
end