From: Brian Candler Date: 2010-03-12T04:11:04+09:00 Subject: Re: Dynamically require and include code in application R. Kumar wrote: > Since include has a problem (NoMethod) What do you mean by this? Show your code. Remember that 'include' has nothing to do with loading code. All it does is make the methods of one module available in another class. Use 'require' to load code. module Foo def say_hello puts "hello" end end class Bar include Foo end Bar.new.say_hello > i tried making the method Class > level, > it works but include does not take a String include takes a Module. If you want to do it dynamically, use const_get. include Object.const_get("Foo") # include ::Foo include Wibble.const_get("Bar") # include Wibble::Bar > I was hoping that the require and include could be at the instance > level, so other objects are not affected. Then maybe you want 'extend' rather than 'include'. 'extend' adds instance methods from a module to a single object. # with module Foo defined as above a = "hello" a.extend Foo a.say_hello # says hello b = "hello" b.say_hello # NoMethodError HTH, Brian. -- Posted via http://www.ruby-forum.com/.