From 4de0a2afbfc851047e20cef28e96d9e982f88096 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 15 Sep 2012 14:48:31 +0900 Subject: Numeric#{upto,downto}: limit may not be an integer --- mrblib/numeric.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'mrblib') diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb index 9f65d5633..c1b6b39c0 100644 --- a/mrblib/numeric.rb +++ b/mrblib/numeric.rb @@ -10,7 +10,6 @@ class Integer # # ISO 15.2.8.3.15 def downto(num, &block) - raise TypeError, "expected Integer" unless num.kind_of? Integer i = self while(i >= num) block.call(i) @@ -38,7 +37,6 @@ class Integer # # ISO 15.2.8.3.27 def upto(num, &block) - raise TypeError, "expected Integer" unless num.kind_of? Integer i = self while(i <= num) block.call(i) -- cgit v1.2.3 From ef17231bd776b266f1fe3132bde0fb6bbef90257 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 15 Sep 2012 15:04:51 +0900 Subject: Integer#step added --- mrblib/numeric.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'mrblib') diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb index c1b6b39c0..1d701b1fc 100644 --- a/mrblib/numeric.rb +++ b/mrblib/numeric.rb @@ -1,6 +1,6 @@ ## # Integer -# +# # ISO 15.2.8 class Integer @@ -44,6 +44,19 @@ class Integer end self end + + ## + # Calls the given block from +self+ to +num+ + # incremented by +step+ (default 1). + # + def step(num, step=1, &block) + i = if num.kind_of? Float then self.to_f else self end + while(i <= num) + block.call(i) + i += step + end + self + end end ## -- cgit v1.2.3