From 364f275997a8deb2972b452f38b7155f21df4e92 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 14 May 2021 08:39:14 +0900 Subject: range.c: implement (part of) `Range#to_a` in C. Mostly for performance reason. --- mrblib/range.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'mrblib') diff --git a/mrblib/range.rb b/mrblib/range.rb index fb217f771..f808053ca 100644 --- a/mrblib/range.rb +++ b/mrblib/range.rb @@ -79,8 +79,18 @@ class Range h end + ## + # call-seq: + # rng.to_a -> array + # rng.entries -> array + # + # Returns an array containing the items in the range. + # + # (1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7] + # (1..).to_a #=> RangeError: cannot convert endless range to an array def to_a - raise RangeError, "cannot convert endless range to an array" if self.last.nil? + a = __num_to_a + return a if a super end alias entries to_a -- cgit v1.2.3