Accessing private members of an outer class in an inner class: JRuby -


i not able access instance variable of outer class in inner class. simple swing app creating using jruby:

class mainapp  def initialize    ...    @textarea = swing::jtextarea.new    @button   = swing::jbutton.new    @button.addactionlistener(buttonlistener.new)     ...  end   class buttonlistener    def actionperformed(e)       puts @textarea.gettext #cant    end  end end 

the workaround can think of this:

... @button.addactionlistener(buttonlistener.new(@textarea)) ...  class buttonlistener   def initialize(control)      @swingcontrol = control   end end 

and use @swingcontrol ins place of @textarea in 'actionperformed' method.

i guess it's not possible directly access outer class members inner class without resorting hacks. because @textarea in buttonlistener class different @textarea in mainapp.

(i'm new ruby, wrong this. so, feel free correct me)


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -