diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-05-14 08:39:14 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-05-14 08:39:14 +0900 |
| commit | 364f275997a8deb2972b452f38b7155f21df4e92 (patch) | |
| tree | 5b2a42ef196c9dbc7644824908e42747ff74a04a /mrblib | |
| parent | 99f0adc3f47d9994a0bc783d9249fb5cf9ac2bb4 (diff) | |
| download | mruby-364f275997a8deb2972b452f38b7155f21df4e92.tar.gz mruby-364f275997a8deb2972b452f38b7155f21df4e92.zip | |
range.c: implement (part of) `Range#to_a` in C.
Mostly for performance reason.
Diffstat (limited to 'mrblib')
| -rw-r--r-- | mrblib/range.rb | 12 |
1 files changed, 11 insertions, 1 deletions
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 |
