-
-
Save Vaguery/723728 to your computer and use it in GitHub Desktop.
| def score(a=0,b=1,c=2,d=3,e=4) | |
| puts "a: #{a.class}" | |
| puts "b: #{b.class}" | |
| puts "c: #{c.class}" | |
| puts "d: #{d.class}" | |
| puts "e: #{e.class}" | |
| scores = Array.new | |
| scores << a << b << c << d << e | |
| total_score = 0 | |
| scores.each do |score| | |
| total_score = total_score + score | |
| end | |
| return total_score | |
| end | |
| puts score(12,13,1,99,2) |
Oh, weird. It interpreted most of it as code, but not the def and the end. (Still learning github)
Updated to see if I'm understanding what you're doing? If you don't get "Fixnum" for each of the arguments, then I'm going to guess it's the interpreter you're running.
I'm doing the ruby koans. And yep, that's really what I'm doing. I have no idea why a thinks it's array.
Here's the weirder part. I replaced my code with yours, and it worked. Then I put my code back, but pasted your def score(... line in place of mine, and it was broken again. I guess I'll keep poking at it for a work around.
Thanks very much for the sanity check.
Actually, this is what it says when I paste your code in place of mine... I missed the first part before. Maybe it's the koans program that's whacking things out. (The warning in the middle there about parentheses and arguments has always been there).
C:\Ruby\koans>rake
(in C:/Ruby/koans)
C:/Ruby/bin/ruby.exe path_to_enlightenment.rb
a: Fixnum
b: Fixnum
c: Fixnum
d: Fixnum
e: Fixnum
127
(eval):1: warning: don't put space before argument parentheses
a: Array
b: Fixnum
c: Fixnum
d: Fixnum
e: Fixnum
AboutScoringProject#test_score_of_an_empty_list_is_zero has damaged your karma.
OH HEY! I know why it did it twice. Cuz a second test ran, when the first one passed. This may be a clue! :)
So I added your puts just below the def, just to make sure i'm not crazy. Sure enough, it said Array, fixnum, fixnum, fixnum, fixnum. Here's the real code
def score(a = 0, b = 0, c = 0, d = 0, e = 0)
#Here's where I added the puts you suggested (a.class, etc)
scores = Array.new
scores << a << b << c << d << e
end