Created
January 19, 2015 06:47
-
-
Save carlesjove/948ff8b59ea60ca1dfe9 to your computer and use it in GitHub Desktop.
SO 28002853
This file contains 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
require "minitest/autorun" | |
12 | |
11 module Numerics | |
10 def twenty_one?(*nums) | |
9 nums.inject(&:+) == 21 | |
8 end | |
7 end | |
6 | |
5 class TestNumerics < MiniTest::Test | |
4 include Numerics | |
3 | |
2 def test_twenty_one? | |
1 assert_equal twenty_one?(3, 4, 5, 6, 3), true | |
14 assert_equal twenty_one?(3, 11, 10), false | |
1 end | |
2 end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Contribution to http://stackoverflow.com/questions/28002853/ruby-adding-numbers-and-printing-true-when-sums-are-21