override the "=" operator in ruby

ruby

Solution

Sorry, you can't do this. When you write `foo = bar`, you're just assigning a variable, not calling any method. It's only `something.foo = bar` that desugars to a method call, and just like everywhere else, the receiver of that method call is the thing before the dot.

Problem

I have a class that has a method: ``` def value=(valueIN) some code end ``` and this does exactly what I want when I do: ``` (class instance).value="new data" ``` It seems like it would be cleaner if I could just override the `=` for this class so I do not have to do `value=`. First, I tried: ``` def =(valueIN) some code end ``` but this gave me an error, so then I tried: ``` def self=(valueIN) some code end ``` This does not cause an error, but it does not work when I do: ``` (class instance)="new data" ``` Is the assignment something that is not changeable at the class level? If this cannot be done, its not really a big deal, but I was hoping I am missing something basic.

Original source