From: Axel Etzold Date: 2008-06-10T06:13:33+09:00 Subject: Re: C++ 2 Ruby -------- Original-Nachricht -------- > Datum: Tue, 10 Jun 2008 05:38:30 +0900 > Von: Jed Kowalski > An: ruby-talk@ruby-lang.org > Betreff: Re: C++ 2 Ruby > Avdi Grimm wrote: > > You might have better luck asking for help with specific sections of > > code, rather than asking us to rewrite a whole program. Try doing a > > best-guest translation to Ruby on your own, and asking about the parts > > you have trouble with. > > ok so, here's the first problem: > def initialize (cen, ile, nn) > @price=cen > @amount=ile > @name=nn > @bought=0 > end > > > def change(x) > amount-- > bought++ > return x-price //WHATS WRONG HERE? > end > > and I get: > > gut.rb:13: void value expression > return x-cena > ^ > gut.rb:13: syntax error, unexpected tIDENTIFIER, expecting kEND > return x-cena > > -- > Posted via http://www.ruby-forum.com/. Jed, you could do this: class MyClass # my most creative invention of a class name attr_accessor :price,:amount,:name,:bought # creates ways to get/set @price,@amount,... from MyClass def initialize (cen, ile, nn) @price=cen @amount=ile @name=nn @bought=0 end def change(x) @amount-=1 @bought+=1 x-self.price end end cen=500 ile=400 nn=4 obj=MyClass.new(cen,ile,nn) p obj.change(1) # -499 =1-500 Read about accessors here: http://www.ruby-doc.org/docs/UsersGuide/rg/accessors.html Best regards, Axel -- Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal f�r Modem und ISDN: http://www.gmx.net/de/go/smartsurfer