tags:

views:

42

answers:

2

Is there any way to do something like this?

a = Struct.new(:c).new(1)
b = Struct.new(:c).new(2)

a.send(:c)
=> 1

b.send(:c)
=> 2

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

The last line result in error:

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

foo.bar = 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.

sepp2k
You mean `bar=`.
Adrian
@Adrian: Yes, I did. Thanks.
sepp2k
+3  A: 

Change the last line to:

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