Method: Range#count
- Defined in:
- range.c
#count ⇒ Integer #count(item) ⇒ Integer #count {|obj| ... } ⇒ Integer
Identical to Enumerable#count, except it returns Infinity for endless ranges.
1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 |
# File 'range.c', line 1724 static VALUE range_count(int argc, VALUE *argv, VALUE range) { if (argc != 0) { /* It is odd for instance (1...).count(0) to return Infinity. Just let * it loop. */ return rb_call_super(argc, argv); } else if (rb_block_given_p()) { /* Likewise it is odd for instance (1...).count {|x| x == 0 } to return * Infinity. Just let it loop. */ return rb_call_super(argc, argv); } else if (NIL_P(RANGE_END(range))) { /* We are confident that the answer is Infinity. */ return DBL2NUM(HUGE_VAL); } else if (NIL_P(RANGE_BEG(range))) { /* We are confident that the answer is Infinity. */ return DBL2NUM(HUGE_VAL); } else { return rb_call_super(argc, argv); } } |