Range#size

What's the size of 1.2..3.4?

Regards,

Dan

···

-----Original Message-----
From: Meinrad Recheis [mailto:meinrad.recheis@gmail.com]
Sent: Thursday, April 13, 2006 7:20 AM
To: ruby-talk ML
Subject: Range#size

dear list,

does anyone object to adding the method :size to class Range?

class Range
  def size
    max-min+1
  end
end

i think it's useful. maybe others too. i'd like to see it
added to the core. here is the test for Range#size in case
it's really added.

def test_range_size
  assert_equal 1, (1..1).size
  assert_equal 2, (1..2).size
  assert_equal 3, (1..3).size
  assert_equal 0, (1..1).size
  assert_equal 1, (1...2).size
end

what do you think?
-- henon

5 ?

:wink:

-a

···

On Thu, 13 Apr 2006, Berger, Daniel wrote:

What's the size of 1.2..3.4?

--
be kind whenever possible... it is always possible.
- h.h. the 14th dali lama