From: Richard Drake Date: 2006-01-25T15:53:12+09:00 Subject: Re: readable and provocative & daring > My apologies if you already realized all that! I did kinda realise all that, except I wasn't focusing on the fact that 'and' is a keyword. Is it only with keywords that the rhs of the operator may not be evaluated? I don't think so - && and || have this property. But I guess they cannot ever be redefined, right? I had small questions and BIG questions here. My BIG questions have to do with what seemed at the time a daring extension of the meaning of '&'. Is such an extension sensible: - 1. just for my project, with four other Rubyists of differing vintages? (I won't tell you what they've said so far, that could spoil the fun!) 2. if we were to release some of our work as open source to the whole wide wonderful world of Ruby programmers? I was starting with a reasonably complex conditional method that used '+' on strings that may be nil. I soon came to realise that a + b works fine when they're both bona fide strings but gives an error when either is nil. On the other hand nil & b is already defined as false, which seems operationally equivalent to nil in every way so is exactly what I want. (Another of my small questions, in passing. Are nil and false ever different in their behavior?) Extending '&' as I have - and the opening up of a core class and method definition is so short and simple, I do love Ruby for that - we now also have "hello " & "cheeky" -> "hello cheeky" "hello " & nil -> nil What's great about this is the amount of brackets and branching it removes from the original method. What's weird about it is this. 12 & 7 -> 4 [3, 6, 9] & [2, 4, 6] -> [6] In other words, '&' always reduces, the result is always <= in some reasonable sense both arguments. Until now. But I still think that, in the highly pragmatic spirit of Ruby, everyone should have such a useful meaning for '&' on Strings. I surely does not harm and fits in brilliantly with the much used blob || "not known" and blob ||= "starter for ten" idioms. But I'm a newb! Thanks very much for the feedback. Richard