From: u235321044@... (Ronald Fischer) Date: 2006-02-27T21:18:35+09:00 Subject: Ruby/Tk: How to access surrounding class from Tk Callback? Assume that I'm modelling a visible form, consisting of entry fields, buttons etc., as a class: require 'tk' class Form def initialize(...) @foo=1234 ... @root=TkRoot.new() { title "My Form" } action_button=TkButton.new(@root) { text "Action!" command { # Do something with @root and @foo puts @root.foo # DOES NOT WORK } } action_button.pack("side" => "right"); end end The problem is with the command routine inside the action_button: Both @root and @foo are undefined here. Obviously, the class context is not present anymore inside this callback function. How would one model this situation in Ruby? In C++ terms: How do I pass the 'this' pointer of my class into the command callback of the button? In my case, I happen to have only one instance of the Form, so I could use a global variable, $form, to hold a reference to my Form object and access it via this global, but of course this solution would be ugly beyond imagination... Kind regards, Ronald -- Sent by mn-pg-p-e-b-consultant-3.com from siemens subdomain of com This is a spam protected message. Please answer with reference header. Posted via http://www.usenet-replayer.com