Hi --

On Mon, 11 Jun 2007, bbiker wrote:

> I am the OP.  Subsequent to my post I also found that #include? would
> return true even though an item is not included (no a member) in a
> range.
>
> irb(main):039:0> ('A'..'IV').include?('A:') => true  # Note   A: is
> NOT a member of 'A'..'IV'
>
> Now in mho, any method that produces incorrect results is buggy!
> whether intentionally or not.

It's a matter of ASCII sorting.  "A:" sorts higher than "A" and lower
than "IV", so it's within that range.

Ranges can be converted into arrays (a little too easily, I sometimes
think), but fundamentally they're not collections.  So it's possible
for this to be true:

   range.include?(val)

while this isn't true:

   range.to_a.include?(val)

There are even ranges that can't be represented as arrays at all
(ranges between floats, for example), and they still have the concept
of inclusion.  The array thing is really just a convenience, offered
where possible but not meant to override the basic idea of the range.


David

-- 
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
    (See what readers are saying!  http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)