[code] loading from the Standard Ruby Libs

[code] loading from the Standard Ruby Libs

Postby Dan Rathbun » Tue Jul 27, 2010 11:21 pm

HappyFileFinder wrote: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:
Code: Select all
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::
Code: Select all
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.
0
Last edited by Dan Rathbun on Wed Jul 28, 2010 9:02 pm, edited 1 time in total.
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: [code] loading from the Standard Ruby Libs

    Postby kwalkerman » Wed Jul 28, 2010 1:17 pm

    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
    0

    kwalkerman 
     

    SketchUcation One-Liner Adverts

    by Ad Machine » 5 minutes ago



    Ad Machine 
    Robot
     



     

    Return to Developers' Forum

    Who is online

    Users browsing this forum: No registered users and 9 guests