On 25 Mar 2011, at 16:07, Robert Klemme wrote:

>>=20
>> Is there a way to define infix operators in Ruby, as I quite like =
this one? :)
>=20
> There is no way to define new operators other than hacking the
> interpreter.  IMHO it's a bad idea to do this just for a minor
> nuisance.

Well, yeah, I won't be hacking the interpreter for this :) Just =
wondering. Is there somewhere I could suggest `+?` as an operator for =
Ruby 2? It was only an off the cuff remark but I quite like it :)

>=20
> I don't understand what's wrong with
>=20
> HEADERS =3D []
> %w{BLAH BLAH_BLAH BLAHHH}.each do |var|
>  x =3D ENV[var] and HEADERS.concat(x.split(/:+/))
> end
>=20
> Nice short concise and yet readable.
>=20

I totally agree, there's nothing wrong with that, and out of the =
suggestions given I think that's the one I like best (which makes me =
feel better for labouring the point:) It's only that, as I said, Ruby =
usually has some really nice shortcuts that don't seem like shortcuts, =
just natural looking. A bit like having to define getters and setters, =
there's nothing wrong with it, but `attr_accessor :var` is really nice, =
as is `||=3D` and it's ilk.

Wouldn't this be quite nice, for instance?

[a,b,c,d].reduce(:+?)

That's all.


Regards,
Iain=