summaryrefslogtreecommitdiffhomepage
path: root/mrblib/range.rb
diff options
context:
space:
mode:
Diffstat (limited to 'mrblib/range.rb')
-rw-r--r--mrblib/range.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/mrblib/range.rb b/mrblib/range.rb
new file mode 100644
index 000000000..79bc40ecd
--- /dev/null
+++ b/mrblib/range.rb
@@ -0,0 +1,30 @@
+#
+# Range
+#
+class Range
+ # 15.2.14.4.4
+ def each(&block)
+ val = self.first
+ unless val.respond_to? :succ
+ raise TypeError, "can't iterate"
+ end
+
+ last = self.last
+ return self if (val <=> last) > 0
+
+ while((val <=> last) < 0)
+ block.call(val)
+ val = val.succ
+ end
+
+ block.call(val) unless exclude_end?
+
+ self
+ end
+end
+
+# include modules
+module Enumerable; end
+class Range
+ include Enumerable
+end