New to Ruby

class ArrayPlus
count = sum = 0
def sums
11.times do
count += 1
sum += count
print "sum at " + count.to_s + “=” + sum.to_s
end

when I executed this code Ruby points at the last line of the code and
gives me this error. me “syntax error, unexpected $end, expecting kEND
end”.

I still can’t understand what I should do to make this code work. Please
point me in the right direction.

thankyou

Gayathri Vijayakumar wrote:

class ArrayPlus
count = sum = 0
def sums
11.times do
count += 1
sum += count
print "sum at " + count.to_s + “=” + sum.to_s
end

when I executed this code Ruby points at the last line of the code and
gives me this error. me “syntax error, unexpected $end, expecting kEND
end”.

I still can’t understand what I should do to make this code work. Please
point me in the right direction.

thankyou

sorry people wrong place to post I suppose, is there a forum for
beginners where I can find some answers?

Gayathri Vijayakumar wrote:

Gayathri Vijayakumar wrote:

class ArrayPlus
count = sum = 0
def sums
11.times do
count += 1
sum += count
print "sum at " + count.to_s + “=” + sum.to_s
end
end

add another ‘end’ to the very bottom

Guest wrote:

Gayathri Vijayakumar wrote:

Gayathri Vijayakumar wrote:

class ArrayPlus
count = sum = 0
def sums
11.times do
count += 1
sum += count
print "sum at " + count.to_s + “=” + sum.to_s
end
end

add another ‘end’ to the very bottom

This is correct, but here’s a bit more explanation: “$end” is the actual
end of the file, whereas “kEND” is the keyword “end”. So it’s basically
saying that it was expecting another keyword end when the file ended, ie
there’s a missing ‘end’ somewhere. In this case, it’s missing from the
end of your ‘do’ block: you need an end for the do, an end for the sums
method and an end for the class.

This is my least favourite thing about ruby - it gives you no feedback
as to where the missing ‘end’ might be.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs