From: timr Date: 2009-08-26T07:45:05+09:00 Subject: Re: Calling method from another class On Aug 24, 3:12 pm, Kostas Lps wrote: > Hi guys, > i have 2 classes say class A and class B. How can the A object that i'll > create to call a class B method???? > Say we have this code: > > class A >   def printA >     puts = "Class A method" >   end > end > > class B >   def printB >     puts "Class B method" >   end > end > > I want to make something like this: > a = A.new > a.printB > > I this possible someway??? I dont want to use modules. > > Thanx in advance > Kostas L. > -- > Posted viahttp://www.ruby-forum.com/. Could you do this: class A def putsFromA puts "hello from A" end end class B def initialize(anA) @anA = anA end def putsFromB puts "hello from B" end def getAMessageFromB @anA.send :putsFromA end end a = A.new b = B.new(a) b.getAMessageFromB # >> hello from A If you made class methods rather than instance methods you could get even closer to the desired syntax: class A def self.putsFromA puts "hello from A" end end class B def self.putsFromB puts "hello from B" end def self.getAMessageFromB A.send :putsFromA end end B.getAMessageFromB # >> hello from A So modules would be one way, using the send method with an symbol representing the name of the method as an argument is another. I think it is closer to what you were hopping for originally. It basically making the B class a proxy for A, at least for one specified method (it receives a method call and forwards it to the actual target class). Tim