Skip to content

Instantly share code, notes, and snippets.

@pasberth
Created September 15, 2011 04:42
Show Gist options
  • Select an option

  • Save pasberth/1218556 to your computer and use it in GitHub Desktop.

Select an option

Save pasberth/1218556 to your computer and use it in GitHub Desktop.
あのさー、Integerはべつにこうでもよくね??
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