diff options
| author | mimaki <[email protected]> | 2012-04-20 09:39:03 +0900 |
|---|---|---|
| committer | mimaki <[email protected]> | 2012-04-20 09:39:03 +0900 |
| commit | e0d6430f63c4cbe0c71ce82ee23284671389a818 (patch) | |
| tree | 41abad7f12eced98d9ac14d141cea62464c3332f /mrblib/numeric.rb | |
| parent | 54ad561098ed353ada70205c39b2c42a2a2eb9e5 (diff) | |
| download | mruby-e0d6430f63c4cbe0c71ce82ee23284671389a818.tar.gz mruby-e0d6430f63c4cbe0c71ce82ee23284671389a818.zip | |
add mruby sources
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 |
