[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 endYou 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 endSometimes 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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better đź’—
Register LoginAdvertisement