Hi all,
Ruby 1.8.2 preview 2
If I have r = Range.new(0,50,true), shouldn't r.end return 49 and not
50? I am confused by this.
If this has come up on the ML in the past, please direct me (and
others) to the thread - I couldn't find it.
Regards,
Dan
PS - I disagree with this behavior.
In mathematical range notation, the difference between 0..50 and
0...50 is [0, 50] and [0, 50). Thus:
irb(main):001:0> a = 0..50
=> 0..50
irb(main):002:0> b = 0...50
=> 0...50
irb(main):003:0> a.include?(49)
=> true
irb(main):004:0> b.include?(49)
=> true
irb(main):005:0> a.include?(49.9)
=> true
irb(main):006:0> b.include?(49.9)
=> true
irb(main):007:0> a.include?(50)
=> true
irb(main):008:0> b.include?(50)
=> false
-austin
···
On Wed, 11 Aug 2004 04:26:15 +0900, Daniel Berger <djberg96@hotmail.com> wrote:
Ruby 1.8.2 preview 2
If I have r = Range.new(0,50,true), shouldn't r.end return 49 and
not 50? I am confused by this.
If this has come up on the ML in the past, please direct me (and
others) to the thread - I couldn't find it.
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca
It doesn't seem quite right that Ruby should do this though
irb(main):001:0> a = (0..50)
a = (0..50)
=> 0..50
irb(main):002:0> b = (0.0..50.0)
b = (0.0..50.0)
=> 0.0..50.0
irb(main):004:0> a.last
a.last
=> 50
irb(main):005:0> a.last.class
a.last.class
=> Fixnum
irb(main):006:0> b.last.class
b.last.class
=> Float
irb(main):007:0> a.include?(49.9)
a.include?(49.9)
=> true
irb(main):008:0> b.include?(49.9)
b.include?(49.9)
=> true
Shouldn't Range#include work differently for integers?
martin
···
Austin Ziegler <halostatue@gmail.com> wrote:
In mathematical range notation, the difference between 0..50 and
0...50 is [0, 50] and [0, 50). Thus:
No. You want Range#member?
----------------------------------------------------- Range#member?
rng.member?(val) => true or false
···
On Thu, 12 Aug 2004 16:01:11 +0900, Martin DeMello <martindemello@yahoo.com> wrote:
Austin Ziegler <halostatue@gmail.com> wrote:
In mathematical range notation, the difference between 0..50 and 0...50 is
[0, 50] and [0, 50). Thus:
It doesn't seem quite right that Ruby should do this though
irb(main):001:0> a = (0..50)
a = (0..50)
=> 0..50
irb(main):002:0> b = (0.0..50.0)
b = (0.0..50.0)
=> 0.0..50.0
irb(main):004:0> a.last
a.last
=> 50
irb(main):005:0> a.last.class
a.last.class
=> Fixnum
irb(main):006:0> b.last.class
b.last.class
=> Float
irb(main):007:0> a.include?(49.9)
a.include?(49.9)
=> true
irb(main):008:0> b.include?(49.9)
b.include?(49.9)
=> true
Shouldn't Range#include work differently for integers?
-------------------------------------------------------------------
Return +true+ if _val_ is one of the values in _rng_ (that is if
+Range#each+ would return _val_ at some point).
-austin
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca
I consider it poor form that in Enumerable, include? and member? are
the same thing, but not so in Range (which includes Enumerable).
Aliases should be a matter of personal taste
Cheers,
Gavin
···
On Thursday, August 12, 2004, 11:19:59 PM, Austin wrote:
Shouldn't Range#include work differently for integers?
No. You want Range#member?