diff options
Diffstat (limited to 'mrblib/numeric.rb')
| -rw-r--r-- | mrblib/numeric.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb new file mode 100644 index 000000000..ee5bdcb56 --- /dev/null +++ b/mrblib/numeric.rb @@ -0,0 +1,42 @@ +# +# Integer +# +class Integer + # 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) + i -= 1 + end + self + end + + # 15.2.8.3.22 + def times(&block) + i = 0 + while(i < self) + block.call(i) + i += 1 + end + self + end + + # 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) + i += 1 + end + self + end +end + +# include modules +module Comparable; end +class Numeric + include Comparable +end |
