[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Implanting a new method for a class

james_b

2/12/2006 8:57:00 PM

Jeppe Jakobsen wrote:
> ...
> I get a NoMethodError on sum. Can anybody tell me what I did wrong here?
> Thanks in advance :)
>

You've defined a class method (e.g. Array.sum)

You need to do this:


class Array
def sum
until (Array.empty?)
...


--
James Britt

http://www.ru... - Ruby Help & Documentation
http://www.artima.c... - The Journal By & For Rubyists
http://www.rub... - The Ruby Store for Ruby Stuff
http://www.jame... - Playing with Better Toys
http://www.30seco... - Building Better Tools