From: Eric Mahurin Date: 2005-08-03T07:34:27+09:00 Subject: Re: [RCR] array or with non-array --- Simon Strandgaard wrote: > Sometimes wish that [3, 5, 13] | [8] can be written as [3, > 5, 13] | 8 > that ary |= 42 would be possible. > > chris2 pointed out that it would be inconsistent with [1,2,3] > + 4. > maybe let + append 4 to the array? > > > > ary = [1, 3, 4] > #=> [1, 3, 4] > > ary |= 2 > #=> [1, 2, 3, 4] > > > > This is another bad idea.. Are you suggesting this or saying it is bad? I don't like it at all. So this is suggesting 2 forms to Array#| and Array#+: array | other_array => array array | element => array If you are looking at combining an element that happens to also be an array, you have an ambiguous situation. It will combine the contents of that array instead of the array. If you want this functionality, you should ask for another method that does this instead of overloading another. There is no disadvantage to this other than having to remember a new method name (and not being able to reuse an operator). The problem is that there is a decision to be made about what to do (combine a single element or an array of them) and that decision is based on what the argument type is (or what methods it responds to). This goes clearly against the duck-typing philosophy where a method should ignore the types of its arguments - it should just use their methods and not worry. OT ... but, the built-in classes of Ruby violate duck-typing all over the place. You'll find lots of examples where: 1) methods have multiple functionalities based on the types of the arguments (usually exact class not just respond_to?). 2) even where a method only has one functionality (or the multiple functionalites are determined by means other than arg type/capabilities - flags, number of args, etc), many/most built-in methods can't take args that have the same capabilities as what is excepted - they only take a certain type or maybe one derived from it. I think this sucks about the Ruby library - that most builtin methods have poor polymorphism/duck-typing of their arguments. ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs