@tig said:
So your code
ABSBMP::MoMo::class_variables
returns an Array of Symbols
>>> [:@@a, :@@b,...]
So you need the step varstr = varstr.to_s to make it into a String.
:@@a >>> "@@a"
Then you use attstr = varstr.gsub(/^[@][@]/, "") to strip off the initial '@@'...
Many of the global query methods changed from Ruby 1.8 to Ruby 2.0.
They now return arrays of symbols (for each variable or method name.) In Ruby 1.8 they returned array of string (for each variable or method name.)
There are also many other "breaking changes" in Ruby 2.0 that need to be dealt with.
(@TIG, Was there a post here on breaking changes?)
Also garbage collection is much better under Ruby 2.0, so any menu reference will most likely only be valid during the evaluation of the file in which the reference is first made by an API call.
So the attempt to hold the reference @@menu[:top] across multiple files may no longer work.
We have been complaining about the non persistence of UI element references, for years! (Especially menu references.)
So the workaround is to save the menu NAME (as a string,) instead of the actual reference to the menu object.
@@menu[:top]= "Plugins"
... then whenever you need the object reference, use:
topmenu = UI.menu( @@menu[:top] )
or
submenu = UI.menu( @@menu[:top] ).add_submenu( "MoMo" )
ðŸ’