From: matt@... (matt neuburg) Date: 2009-05-12T22:40:08+09:00 Subject: Re: inheritance in ruby jarodzz wrote: > class Page > @url="" > > def initialize > puts "going to "+@url > end > end > > class MainPage < Page > @url = "Main" > end > > class LoginPage < Page > @url = "Login" > end The problem is that the @url mentioned in the first line of each class definition and the @url mentioned in the initialize method are not the same. This is a common beginner mistake. The way to speak of an instance variable is from inside an instance method (during code that runs inside an instance). So: class Page def initialize puts "going to "+@url end end class MainPage < Page def initialize @url = "Main" super end end class LoginPage < Page def initialize @url = "Login" super end end m. -- matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/ Leopard - http://www.takecontrolbooks.com/leopard-customizing.html AppleScript - http://www.amazon.com/gp/product/0596102119 Read TidBITS! It's free and smart. http://www.tidbits.com