Project

General

Profile

Feature #11917 ยป 0001-Make-Range-size-an-alias-of-Range-length.patch

avit (Andrew Vit), 01/30/2016 07:01 AM

View differences:

range.c
rb_define_method(rb_cRange, "last", range_last, -1);
rb_define_method(rb_cRange, "min", range_min, -1);
rb_define_method(rb_cRange, "max", range_max, -1);
rb_define_method(rb_cRange, "size", range_size, 0);
rb_define_method(rb_cRange, "length", range_size, 0);
rb_define_alias(rb_cRange, "size", "length");
rb_define_method(rb_cRange, "to_s", range_to_s, 0);
rb_define_method(rb_cRange, "inspect", range_inspect, 0);
test/ruby/test_range.rb
assert_equal 42, (1..42).each.size
end
def test_length
assert_equal 42, (1..42).length
assert_equal 41, (1...42).length
end
def test_bsearch_typechecks_return_values
assert_raise(TypeError) do
(1..42).bsearch{ "not ok" }
    (1-1/1)