Created
September 15, 2011 04:42
-
-
Save pasberth/1218556 to your computer and use it in GitHub Desktop.
あのさー、Integerはべつにこうでもよくね??
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Integer | |
| include Enumerable | |
| def each(&blk) | |
| times(&blk) | |
| end | |
| end | |
| if __FILE__ == $PROGRAM_NAME | |
| require "test/unit" | |
| class TestEnumint < Test::Unit::TestCase | |
| def setup; end | |
| def test_each | |
| result = [] | |
| 3.each { |i| result << i } | |
| assert_equal [0, 1, 2], result | |
| end | |
| def test_inject | |
| assert_equal 6, 4.inject(0) { |sum, i| sum + i } | |
| end | |
| def test_map | |
| assert_equal [0, 1, 2], 3.map { |i| i } | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment