summaryrefslogtreecommitdiffhomepage
path: root/mrblib
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2020-10-15 18:35:13 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2020-10-15 18:35:13 +0900
commit6b457d2c006c333bfdc1328ecc73db7e63a6aca5 (patch)
treed4175aeefd1bf78893e21dda70615127594ad29f /mrblib
parentc779413df39ef7d96583bda08104491c55049fad (diff)
parentbec4d053400c3a11c8efd68c3e8bd5ea4a0bcc54 (diff)
downloadmruby-6b457d2c006c333bfdc1328ecc73db7e63a6aca5.tar.gz
mruby-6b457d2c006c333bfdc1328ecc73db7e63a6aca5.zip
Merge branch 'work_for_merge' of https://github.com/zubycz/mruby into zubycz-work_for_merge
Diffstat (limited to 'mrblib')
-rw-r--r--mrblib/range.rb26
1 files changed, 24 insertions, 2 deletions
diff --git a/mrblib/range.rb b/mrblib/range.rb
index 9f94f35d1..36886d50c 100644
--- a/mrblib/range.rb
+++ b/mrblib/range.rb
@@ -12,8 +12,25 @@ class Range
def each(&block)
return to_enum :each unless block
- val = self.first
- last = self.last
+ val = self.begin
+ last = self.end
+
+ if val.kind_of?(Fixnum) && last.nil?
+ i = val
+ while true
+ block.call(i)
+ i += 1
+ end
+ return self
+ end
+
+ if val.kind_of?(String) && last.nil?
+ if val.respond_to? :__upto_endless
+ return val.__upto_endless(&block)
+ else
+ str_each = true
+ end
+ end
if val.kind_of?(Integer) && last.kind_of?(Integer) # fixnums are special
lim = last
@@ -56,6 +73,11 @@ class Range
h += 1 if self.exclude_end?
h
end
+
+ def to_a
+ raise RangeError, "cannot convert endless range to an array" if self.last.nil?
+ super
+ end
end
##