Forum: RForum new to Ruby

Posted by 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
Posted by 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?
Posted by 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
Posted by 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.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.