Skip to content

Instantly share code, notes, and snippets.

@Vaguery
Created December 1, 2010 16:26
Show Gist options
  • Select an option

  • Save Vaguery/723728 to your computer and use it in GitHub Desktop.

Select an option

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)
@onealexharms
Copy link
Copy Markdown

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

total_score = 0
scores.each do |score|
total_score = total_score + score
end
    return total_score

end

@onealexharms
Copy link
Copy Markdown

Oh, weird. It interpreted most of it as code, but not the def and the end. (Still learning github)

@Vaguery
Copy link
Copy Markdown
Author

Vaguery commented Dec 1, 2010

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.

@onealexharms
Copy link
Copy Markdown

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.

@onealexharms
Copy link
Copy Markdown

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.

@onealexharms
Copy link
Copy Markdown

OH HEY! I know why it did it twice. Cuz a second test ran, when the first one passed. This may be a clue! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment