From: Jim Bartlett Date: 2002-09-28T04:24:43+09:00 Subject: Re: Programming Ruby p103 (Pragmatic Programmer) That was it. I was using puts (1..4).sum. I appreciate all the input from everyone. Thanks for your help! Jim. "Kent Dahl" wrote in message news:3D94A298.E3578167@stud.ntnu.no... > Jim Bartlett wrote: > > > > I created the "Inject" module as shown in Programming Ruby, p102-103 and > > included it in the Range class. When I try to get the sum of a range (ie > > (1..4).sum), it just spits out 1..4 and then an error: > > > > undefined method "sum" for nil (NameError) > > > > It works fine for arrays when included in class Array. What have I missed? > > Thanks. > > Let me take a wild guess: You're using puts or print to print the value > and write: > puts (1..4).sum > or something similar? The puts assumes the parenthesis as its argument > list, and what is returned by puts (nil) is the object that gets the sum > message. Try extra parenthesis. > puts ((1..4).sum) > > -- > (\[ Kent Dahl ]/)_ _~_ __[ http://www.stud.ntnu.no/~kentda/ ]___/~ > ))\_student_/(( \__d L b__/ NTNU - graduate engineering - 5. year ) > ( \__\_�|�_/__/ ) _)Industrial economics and technological management( > \____/_�_\____/ (____engineering.discipline_=_Computer::Technology___)