[code] loading from the Standard Ruby Libs
-
@unknownuser said:
Ok, found a copy [of a Standard Ruby Lib file ] here: [...URL to Jim Foltz' webpage snipped...] if anyone needs it in the future.
I don't really think Jim meant to be serving up Ruby Standard Libs for general use. For his plugin perhaps, but a well written plugin should first attempt to load the library from the user's standard Ruby install, and then only load a 'plugin packaged' version if the user's system does not have a full Ruby install.
You can run into version mis-match bugs, etc.
Code snippet:
unless defined?(ExtendedRubyClassNameHere) begin # attempt to load from Std Lib require('extendedrubylibfile.rb') rescue LoadError # Woops! Load a plugin supplied copy require('pluginsubfolder/extendedrubylibfile.rb') end end
You can get fancy and check the user's RUBY_VERSION, but really if the user has not installed a full Ruby install, they will be running v.1.8.0 (on Win32) and v.1.8.5 (on Mac,) so you might consider suppling v.1.8.0 & v.1.8.5 Ruby backup libs with your plugins.
hhmm.. code would be::unless defined?(ExtendedRubyClassNameHere) begin # attempt to load from Std Lib require('extendedrubylibfile.rb') rescue LoadError # Woops! Load a plugin supplied copy if RUBY_VERSION=='1.8.0' require('pluginsubfolder/1.8.0/extendedrubylibfile.rb') else # prob on a Mac require('pluginsubfolder/1.8.5/extendedrubylibfile.rb') end end end
Sometimes the code in certain Ruby lib scripts does not change for many versions, so sometimes the choice is a bit simplier.
COMMUNITY CONTENT - Public Domain - Author claims no copyright.
Moderators may edit post / correct code snippet(s) at will. -
Dan,
Very helpful, as always.
So... For future... this is where you can download the library files if you need to: http://www.ruby-lang.org/en/downloads/
Thanks again!
--
Karen
Advertisement