M
Mike Austin
I'm building a view hierarchy from a file, and I would like it to add getter
methods for every subview created. For example, I should be able to write:
window.bottom_panel.save_button.left = 20
I played around with singleton classes and define_method, am I close? I wonder
if it is illegal to do 'class << self end' within a method - I get the error
'class definition in method body'
hierarchy.each do |key, value|
view = Object::const_get( key[1] ).new
class << self end
self.class.class_eval do
define_method( key[1] ) do
return view
end
end
end
hierarchy = {
[:bottom_panel, anel] => {
[:save_button, :Button] => {}
}
}
Thanks,
Mike
methods for every subview created. For example, I should be able to write:
window.bottom_panel.save_button.left = 20
I played around with singleton classes and define_method, am I close? I wonder
if it is illegal to do 'class << self end' within a method - I get the error
'class definition in method body'
hierarchy.each do |key, value|
view = Object::const_get( key[1] ).new
class << self end
self.class.class_eval do
define_method( key[1] ) do
return view
end
end
end
hierarchy = {
[:bottom_panel, anel] => {
[:save_button, :Button] => {}
}
}
Thanks,
Mike