From: "Brian Schröder" Date: 2005-10-20T22:55:56+09:00 Subject: Re: Unit testing an each function On 20/10/05, Kevin Ballard wrote: > Brian Schr�der wrote: > > > [snip] > > > > > > (1..100).reject.even? > > > > > > [snip] > > > > Just wanted to state that on second reading of this thread it again > > did hurt in my eyes. If I read (1.100).reject I expect a resulting > > array. And when I read the above I wondered shortly if even? works on > > arrays maybe returning true if the array has an even number of > > entries. Then I remembered the thread topic and started this text. So > > a > > -1 > > from me for proposing this as an addition to the language. > > Except that (1..100).reject doesn't return an array at all unless a > block is supplied - it gives a LocalJumpError. All the enumerating > methods I've tested except for Enumerable#collect give an error when > called without a block (#collect without a block is equivalent to > #to_a). So with this change, the case where no block is supplied > becomes useful as opposed to useless (and in the #collect case, I can't > imagine anybody's actually relying on #collect being equivalent to > #to_a when called without a block, because they should be using #to_a > directly for that). > > In any case, I wasn't proposing this as an addition to the language > (not that I would mind), I was simply proposing this as something I > should package up into a gem so people could use it if they wanted. > Hello Kevin, it is clear that reject without a block does not work, it was more a question of visual parsing. Reject without a block has no meaning, because we need to tell what to reject. And telling this is done with a block. Your quite intelligent magic gives IMHO a wrong meaning to the dot operator. You seem not to call .even? on the result of a reject. Well effectively you do, but I read chained methods as doing a chain of succeding operations on a chain of objects, and that is not what I read when I read (1..100).reject.even? Therefore I proposed (1..100).reject :even?, because there it is made clearer that even is given to reject to do something. Nonetheless go ahed and package it as a gem. I just wanted to voice what was disturbing me with this syntax. Best regards, Brian -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/