summaryrefslogtreecommitdiffhomepage
path: root/mrblib/range.rb
diff options
context:
space:
mode:
authormimaki <[email protected]>2012-04-20 09:39:03 +0900
committermimaki <[email protected]>2012-04-20 09:39:03 +0900
commite0d6430f63c4cbe0c71ce82ee23284671389a818 (patch)
tree41abad7f12eced98d9ac14d141cea62464c3332f /mrblib/range.rb
parent54ad561098ed353ada70205c39b2c42a2a2eb9e5 (diff)
downloadmruby-e0d6430f63c4cbe0c71ce82ee23284671389a818.tar.gz
mruby-e0d6430f63c4cbe0c71ce82ee23284671389a818.zip
add mruby sources
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