--000e0cd6668e04b004049f534a68
Content-Type: text/plain; charset=ISO-8859-1

...personally i think it would be nice to be able to define new operators
(like the aforementioned +?) that way when a situation like this comes up,
one can simply:

op_def +?  # maybe? i'm assuming it'd have special syntax...
  # stuff
end

and get on with life, making your code cleaner & simpler.  IDK how well this
would work or its potential ramifications, but i think it fits into the
'flavor' of ruby to be able to do such things (i mean, you can define/change
damn near *everything else* in the language, why not operators?)
hex



On Fri, Mar 25, 2011 at 12:54 PM, Iain Barnett <iainspeed / gmail.com> wrote:

>
> On 25 Mar 2011, at 16:07, Robert Klemme wrote:
>
> >>
> >> Is there a way to define infix operators in Ruby, as I quite like this
> one? :)
> >
> > 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 :)
>
> >
> > I don't understand what's wrong with
> >
> > HEADERS  ]
> > %w{BLAH BLAH_BLAH BLAHHH}.each do |var|
> >  x  NV[var] and HEADERS.concat(x.split(/:+/))
> > end
> >
> > Nice short concise and yet readable.
> >
>
> 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 `||and it's
> ilk.
>
> Wouldn't this be quite nice, for instance?
>
> [a,b,c,d].reduce(:+?)
>
> That's all.
>
>
> Regards,
> Iain
>

--000e0cd6668e04b004049f534a68--