Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does Ruby include? evaluate to nil?
    text
    copied!<p>So, I'm a total nuby working through <a href="http://www.rubykoans.com/" rel="nofollow noreferrer">http://www.rubykoans.com/</a> and I'm stuck on about_scoring_project.rb. This is my stab at the score method. </p> <pre><code>def score(dice) score = 0; if dice.respond_to?("include?") then # add 1000 points if rolled 3 ones score += 1000 if dice.include?([1, 1, 1]) # add 100 points times die face value if rolled 3 of a number between 2 and 6 (2...6).each do |die| score += die*100 if dice.include?([die, die, die]) # award points for each 1 or 5 not a part of a set of 3 leftovers = dice - [1,1,1] leftovers -= [5,5,5] leftovers.each do |leftover| score += 100 if leftover == 1 score += 50 if leftover == 5 end end end score end class AboutScoringAssignment &lt; EdgeCase::Koan def test_score_examples assert_equal 1150, score([1,1,1,5,1]) assert_equal 0, score([2,3,4,6,2]) assert_equal 350, score([3,4,5,3,3]) assert_equal 250, score([1,5,1,2,4]) end end </code></pre> <p>In the call to score from the first assert_equal, I would expect dice.include?([1,1,1]) to evaluate to true, but it's evaluating to nil (and score is returning 0 instead of 1150).</p> <p>I tried this separately...</p> <pre><code>require 'test/unit' class EnumerableTests &lt; Test::Unit::TestCase def test_include my_enumerable = [1,1,1,5,1] assert true, my_enumerable.include?([1,1,1]) end end </code></pre> <p>...and the test passes, so I don't know why I'm getting nil in my score method. </p> <p>Anybody see what I'm doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload