From: "Erik Bågfors" Date: 2001-10-28T01:02:12+09:00 Subject: [ruby-talk:23632] Re: sleeping, calling methods inside class defs On Sat, 2001-10-27 at 17:52, Tobias Reif wrote: > David, Guy, > > thanks a lot for your help. > > In the following: what would be the most convenient and elegant way to > omit the line > t.assign_hey_ho_string > (and perhaps more code)? > > ----- > class Tobi > > def hey > "hey!\n" > end > def ho > "ho!\n" > end > > def assign_hey_ho_string > @hey_ho_string = hey + ho > end > > def hey_ho_string > @hey_ho_string > end > > end > > t = Tobi.new > > t.assign_hey_ho_string > > puts t.hey_ho_string > ----- > > I now know that I can't just call > @hey_ho_string = hey + ho > inside the classdef. > > What would be a good way to achieve the same effect in this case, > without having to call the assign method from the object? > If I understand you correctly class Tobi def hey "hey!\n" end def ho "ho!\n" end def initialize @hey_ho_string = hey + ho end attr_reader :hey_ho_string end Tobi.new.hey_ho_string -- Erik B�gfors | erik@bagfors.nu Supporter of free software | GSM +46 733 279 273 fingerprint: 6666 A85B 95D3 D26B 296B 6C60 4F32 2C0B 693D 6E32 -- Erik B�gfors | http://www.ardendo.se/ Erik.Bagfors@ardendo.se | GSM +46 733 279 273 fingerprint: 6666 A85B 95D3 D26B 296B 6C60 4F32 2C0B 693D 6E32