From: Rick DeNatale Date: 2009-05-12T20:31:06+09:00 Subject: Re: inheritance in ruby On Tue, May 12, 2009 at 6:47 AM, jarodzz wrote: > Hi, all. > I'm really new to Ruby. Got this error: > > class Page >    @url="" > >    def initialize >        puts "going to "+@url >    end > end > > class MainPage < Page >    @url = "Main" > end > > class LoginPage < Page >    @url = "Login" > end > > every time a page is created, I want it to go to its own url. > > m = MainPage.new() > # should print going to Main > l = LoginPage.new() > # should print going to Login > > But I tried @@, @ and found neither of them works. > > Anyone knows what kind of method or variable I could use? It the url is fixed for all instances of each class I wouldn't use a variable at all: class Page def initialize puts "going to "+ url end end class MainPage < Page def url "Main" end end class LoginPage < Page def url "Login" end end -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale