Sergey Sergey - 1 year ago 84
Ruby Question

Ruby: using Object.send for assigning variables

Is there any way to do something like this?

a =
b =

=> 1

=> 2

a.send(:c) = b.send(:c)

The last line result in error:

syntax error, unexpected '=', expecting $end
a.send(:c) = b.send(:c)

Answer Source
a.send(:c=, b.send(:c)) = baz isn't a call to the method bar followed by an assignment - it's a call to the method bar=. So you need to tell send to call that method.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download