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
1336 1336
    rb_define_method(rb_cRange, "last", range_last, -1);
1337 1337
    rb_define_method(rb_cRange, "min", range_min, -1);
1338 1338
    rb_define_method(rb_cRange, "max", range_max, -1);
1339
    rb_define_method(rb_cRange, "size", range_size, 0);
1339
    rb_define_method(rb_cRange, "length", range_size, 0);
1340
    rb_define_alias(rb_cRange,  "size", "length");
1340 1341
    rb_define_method(rb_cRange, "to_s", range_to_s, 0);
1341 1342
    rb_define_method(rb_cRange, "inspect", range_inspect, 0);
1342 1343

  
test/ruby/test_range.rb
429 429
    assert_equal 42, (1..42).each.size
430 430
  end
431 431

  
432
  def test_length
433
    assert_equal 42, (1..42).length
434
    assert_equal 41, (1...42).length
435
  end
436

  
432 437
  def test_bsearch_typechecks_return_values
433 438
    assert_raise(TypeError) do
434 439
      (1..42).bsearch{ "not ok" }
435
-