• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

[code] loading from the Standard Ruby Libs

Scheduled Pinned Locked Moved Developers' Forum
2 Posts 2 Posters 1.2k Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    Dan Rathbun
    last edited by Dan Rathbun 27 Jul 2010, 22:21

    @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.

    I'm not here much anymore.

    1 Reply Last reply Reply Quote 0
    • K Offline
      kwalkerman
      last edited by 28 Jul 2010, 12:17

      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

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      1 / 1
      • First post
        1/2
        Last post
      Buy SketchPlus
      Buy SUbD
      Buy WrapR
      Buy eBook
      Buy Modelur
      Buy Vertex Tools
      Buy SketchCuisine
      Buy FormFonts

      Advertisement