Class: PassAlong

Inherits:
Object
  • Object
show all
Defined in:
lib/husky/pass_along.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sender, receiver, method) ⇒ PassAlong

Returns a new instance of PassAlong.



11
12
13
14
15
# File 'lib/husky/pass_along.rb', line 11

def initialize(sender, receiver, method)
  @sender = sender
  @receiver = receiver
  @method = method
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/husky/pass_along.rb', line 9

def method
  @method
end

#receiverObject (readonly)

Returns the value of attribute receiver.



9
10
11
# File 'lib/husky/pass_along.rb', line 9

def receiver
  @receiver
end

#senderObject (readonly)

Returns the value of attribute sender.



9
10
11
# File 'lib/husky/pass_along.rb', line 9

def sender
  @sender
end

Class Method Details

.all_variables(sender, receiver) ⇒ Object



3
4
5
6
7
# File 'lib/husky/pass_along.rb', line 3

def self.all_variables(sender, receiver)
  sender.class.instance_methods(false).each do |method|
    new(sender, receiver, method).run
  end
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
# File 'lib/husky/pass_along.rb', line 17

def run
  sender.class.after method do |*, obj|
    variables = get_variables_from(sender)
    variables.each do |var|
      receiver.instance_variable_set(var, sender.instance_variable_get(var))
    end
  end
end