From: "Jesús Gabriel y Galán" Date: 2010-10-21T17:06:08+09:00 Subject: Re: scope when reopening method On Thu, Oct 21, 2010 at 9:23 AM, Rahul Kumar wrote: > Here is a dummy class with a method "meth". > >   class My > >      # str contains some value generated by My >      def meth str >      end > >      def call_meth >         meth "abc" >      end >   end > > >   # ------ my application starts here > >   arr = [] > >   m = My.new >   def m.meth(str) >     # access some other object in application scope >     arr << str >     do_something str # call some method in my app >   end > > I have the method "meth" above which is of interest to user apps. > The app overrides the method and would like to access methods or > variables > in my application scope. > > Is there anyway this is possible (other than using global variables) ? > To me it appears that meth() can only access what is in that objects > scope plus globals. thx. If I understand correctly, you want the meth method defined for object a to be able to access methods and instance variables defined in the My class. Nothing special needs to be done: irb(main):001:0> class My irb(main):002:1> def initialize irb(main):003:2> @value = 3 irb(main):004:2> end irb(main):005:1> def do_something irb(main):006:2> puts "my value is #{@value}" irb(main):007:2> end irb(main):008:1> def call_meth irb(main):009:2> meth "abc" irb(main):010:2> end irb(main):011:1> def meth str irb(main):012:2> str * 2 irb(main):013:2> end irb(main):014:1> end => nil irb(main):015:0> My.new.call_meth => "abcabc" irb(main):016:0> a = My.new irb(main):025:0> def a.meth str irb(main):026:1> do_something irb(main):027:1> str + @value.to_s irb(main):028:1> end => nil irb(main):029:0> a.call_meth my value is 3 => "abc3" Maybe I misunderstood the question. Jesus.