Class: Farm::PerformableMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/farm/performable_method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, method_name, args) ⇒ PerformableMethod

Returns a new instance of PerformableMethod.

Raises:

  • (NoMethodError)


9
10
11
12
13
14
15
# File 'lib/farm/performable_method.rb', line 9

def initialize(object, method_name, args)
  raise NoMethodError, "undefined method `#{method_name}' for #{object.inspect}" unless object.respond_to?(method_name, true)

  self.object       = object
  self.args         = args
  self.method_name  = method_name.to_sym
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



25
26
27
# File 'lib/farm/performable_method.rb', line 25

def method_missing(symbol, *args)
  object.send(symbol, *args)
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



5
6
7
# File 'lib/farm/performable_method.rb', line 5

def args
  @args
end

#method_nameObject

Returns the value of attribute method_name.



5
6
7
# File 'lib/farm/performable_method.rb', line 5

def method_name
  @method_name
end

#objectObject

Returns the value of attribute object.



5
6
7
# File 'lib/farm/performable_method.rb', line 5

def object
  @object
end

Instance Method Details

#display_nameObject



17
18
19
# File 'lib/farm/performable_method.rb', line 17

def display_name
  "#{object.class}##{method_name}"
end

#performObject



21
22
23
# File 'lib/farm/performable_method.rb', line 21

def perform
  object.send(method_name, *args) if object
end

#respond_to?(symbol, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/farm/performable_method.rb', line 29

def respond_to?(symbol, include_private=false)
  super || object.respond_to?(symbol, include_private)
end