A
Albert Schlef
It occurred to me several times that I wanted to do:
@cars.each do |owner, model|
widget = TkLabel.newtext => model)
def widget.get_owner
return owner
end
end
But, of course, this doesn't work because the code inside 'def' doesn't
see the enveloping variables, so the 'owner' within the 'def' isn't
recognized.
So instead I do:
@cars.each do |owner, model|
widget = TkLabel.newtext => model)
meta = (class << widget; self; end)
meta.senddefine_method, :get_owner) do
return owner
end
end
It work. Yet, it looks a bit ugly. Is there any "nicer" way I'm missing?
@cars.each do |owner, model|
widget = TkLabel.newtext => model)
def widget.get_owner
return owner
end
end
But, of course, this doesn't work because the code inside 'def' doesn't
see the enveloping variables, so the 'owner' within the 'def' isn't
recognized.
So instead I do:
@cars.each do |owner, model|
widget = TkLabel.newtext => model)
meta = (class << widget; self; end)
meta.senddefine_method, :get_owner) do
return owner
end
end
It work. Yet, it looks a bit ugly. Is there any "nicer" way I'm missing?