Forum: Ruby-Forum.com new to Ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
335ddd0235f9de2c033efde30af5dd20?d=identicon&s=25 Gayathri Vijayakumar (fairylights)
on 2007-04-06 07:38
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
335ddd0235f9de2c033efde30af5dd20?d=identicon&s=25 Gayathri Vijayakumar (fairylights)
on 2007-04-06 07:43
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?
9276a76376fa6acbec97c3937fabc2d8?d=identicon&s=25 Guest (Guest)
on 2007-05-19 23:16
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
73c04e9ef9ca435c5b19a2e765ae6d20?d=identicon&s=25 Max Williams (max-williams)
on 2007-07-02 01:47
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 topic is locked and can not be replied to.