Afficher un message
Vieux 21/02/2008, 15h10   #2
Ilan Berci
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to define the assignment operator in Ruby ?

Stephane Wirtel wrote:

>
> I don't believe that's possible to assign something to an instance
>
> Best Regards,
>
> Stephane


Stephanie,

In ruby, we don't assign to an instance as you mentioned, we assign to a
variable that can hold any type. We therefore can't override the
assignment operator.

BUT you can override an assignment operation.. such as

class Foo
def bar= (val)
@bar = val
p "I am assigning #{val} to @bar"
end

hth

ilan

--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
 
Page generated in 0,05099 seconds with 9 queries