[fxruby-users] storing widget references in hash

Jannis Pohlmann info at sten-net.de
Mon May 16 06:11:32 EDT 2005


Jacob Hanson schrieb:

>Hello List,
>
>I'm keeping an hash of controls I create, e.g.
>
>myArray['label'] = FXLabel.new(...
>myArray['dropdown'] = FXComboBox.new(...
>
>But, if I 'p' the hash, instead of seeing references to the widget
>objects, all that gets stored are the labels for the controls, as if I
>was saying FXComboBox.new().to_s. But I'm not. Hash doesn't do an
>internal type conversion of values does it? Any other reason why I
>would be seeing this?
>
>Thanks,
>  
>
Hi Jacob.

That's due to the overloaded .to_s functions in (nearly) all FXRuby 
classes. To ensure
you still have references to the objects instead of just their labels in 
your hash try to
call

    myArray.each_value do |val|
       puts val.class
    end

If you get Fox::FXLabel and Fox::FXComboBox as output everything is 
still ok.

By the way, an example for a FXRuby class which has no overloaded .to_s 
function
is FXFont:

     puts FXFont.new(getApp, "verdana", 10)

Regards,
Jannis


More information about the fxruby-users mailing list