From: 7stud -- Date: 2008-01-31T16:56:47+09:00 Subject: Re: Referring to method in enclosing class Richard Everhart wrote: > I need to do something like what is being attempted in the code below. > > The commented out code is what I can't figure out: how do methods in a > nested classes call methods in their enclosing class? Is this even > possible? > > class Enclosing > def go > Hello.new.do_say_hello > end > > def say_hello > "Hello World!" > end > > class Hello > def do_say_hello > # puts Enclosing class's say_hello method > end > end > > end Why do you want to nest Hello inside Enclosing? class Enclosing def say_hello puts "hi" end end class Hello def initialize @e = Enclosing.new end def do_say_hello @e.say_hello end end h = Hello.new h.do_say_hello --output:-- hi -- Posted via http://www.ruby-forum.com/.