-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 08.06.2012 10:57, schrieb Jan E.:
> Hi,
> 
> You actually *can* assign multiple values, if you use assignment
> syntax:
> 
> my_object.val = 1, 2
> 
> This will wrap 1 and 2 into an array and assign it to the single 
> parameter of the val= method. Not exactly what you want, but it
> works just as well.

Not necessarily. The array is only assigned to the parameter if Ruby
doesn¡Çt find anything else to assign to.

# ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
irb(main):001:0> class Foo
irb(main):002:1> def foo=(val)
irb(main):003:2> p val
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> f = Foo.new
=> #<Foo:0x00000002704430>
irb(main):007:0> f.foo = 1, 2
[1, 2]
=> [1, 2]
irb(main):008:0> x, f.foo = 1, 2  #<----
2
=> [1, 2]
irb(main):009:0> x
=> 1
irb(main):010:0>

This way, x gets the 1 and the foo= assignment method gets the 2.

> Anyway, I think you shouldn't use = methods the way you do. They
> are not meant to be called directly and used as normal methods.
> Their only purpose is to fake the attribute syntax of classical
> object oriented languages.

Agreed.

Valete,
Marvin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJP0fjSAAoJELh1XLHFkqhaESkH/2LDd4Wmt6ufa4aouWxTD/Yc
5O4trypQwBjFUL4Tbn6wIdGRsnfM0KxOw2yHzEg10rj24goasZvk3MpeLLPvpg4Z
SUVob5XuwV051Rx9l0ViHQrTVN6ajUCaq/Me2PFNHCFOxgwG67v81lWSUrjVNaaP
fnRwNG1Q5P8Z4+POAMya2TpxKv+8PsXi+JRMWgVw2t5yxkY9ob1cklDiHsgRVcKC
XbjllPoTbTHg/7/rvjNoD7UENUYII0DwD1vlm7Qgp9sDhMGUHzoAEBakyU5K436+
VTRNNReE1d18x0W5lhXq22iSzvAAS8Z3kK/SbVdPWTRqwQMDsfC5226xRqAO938=
=Hd35
-----END PGP SIGNATURE-----