sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    [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.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by Dan Rathbun

      @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

        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
        • First post
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement