On Fri, Mar 25, 2011 at 4:42 PM, Iain Barnett <iainspeed / gmail.com> wrote:
>
> On 25 Mar 2011, at 14:32, Colin Bartlett wrote:
>
>> On Fri, Mar 25, 2011 at 7:52 AM, Robert Klemme
>> <shortcutter / googlemail.com> wrote:
>>> What about
>>> ...
>>> res = [1]
>>> [a,b,c].each {|x| x and res.concat x}
>>
>> I'd also wondered whether Iain Barnett really needed array + array2
>> rather than array.concat(array2), and wondered about something
>> similar:
>>
>> class Array
>>   >>     >>  >>  
>>   >>   
>>  
>>  
>> end
>>
>
> I really appreciate the responses, but if I apply them to the code that provoked the question for me, and my dislike of wrapping things in an array only to get access to a function or block (which also then removes the wrapper), and of creating locals for a single use, then I'm not so sure they work.

Maybe you should reduce your requirements...

> As in, there are so many great shortcuts in Ruby that feel very natural too, that some kind of infix operator works well for args split over severalines due to their length.
>
> I think this reads very easily, HEADERS is 3 env vars added up into one:
>
>   ۢȢ >  ۢȢ 
>  ۢȢ>
> to this, which creates an array then destroys it, which kind of masks thentention:
>
>   >  ۢȢݬ
>  ۢȢ>  ۢȢ>  ®۱ݩ   
>
> If I was going to use a fold or something similar then I would probably have done something like this, or used a ternary operator in a fold, (knowing the way I think):
>
>   >  ۢȢݬ
>  ۢȢ>  ۢȢ>  ® 娺
>
> but compared to this it seems a bit creaky:
>
>   ۢȢ 
>  ۢȢ >  ۢȢ>
> 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.

> Actually, looking at the code they'd be ENV["BLAH_BLAH"].split(":") as they were PATHs, but I'm not sure the inclusion adds anything to the examples.

I don't understand what's wrong with

HEADERS = []
%w{BLAH BLAH_BLAH BLAHHH}.each do |var|
  x = ENV[var] and HEADERS.concat(x.split(/:+/))
end

Nice short concise and yet readable.

Cheers

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/