Help us understand the problem. What is going on with this article?

SketchUpで、Rubyの標準ライブラリを使う(OSX版)

More than 5 years have passed since last update.

SketchUpに組み込まれているRubyエンジンは標準ライブラリのサブセットのため、標準ライブラリをrequireすると、no such file errorが発生します。

それを解消するためのスクリプトを紹介します。

 loadpaths.rb
    #  file: '!loadpaths.rb'
    #  for mac OS X
    #
    #  Version 3.0.1   -  Public Domain
    #
    #  Authored by  :  Dan Rathbun
    #  Contributors :  Satrex
    #
    begin
      #
      # TWEEKER variables
      #
      # may change 'ver' to a literal string
      if RUBY_VERSION < '1.9.0'
        ver=RUBY_VERSION.split('.')[0..1].join('.')
      else
        ver=RUBY_VERSION
      end
      #
      # 'pre' is the rubylib path prefix
      pre='/usr/local/bin/ruby'<<RUBY_VERSION.split('.').join<<'/lib/ruby'
      #
      plat=RUBY_PLATFORM
      #
      # add the standard lib path
      $LOAD_PATH << "#{pre}/#{ver}"
      # add the standard platform sub lib path
      $LOAD_PATH << "#{pre}/#{ver}/#{plat}"
      #
      # optionally add paths to vendor_ruby libs
      # only apply if there are things installed there
      #$LOAD_PATH << "#{pre}/vendor_ruby/#{ver}"
      #$LOAD_PATH << "#{pre}/vendor_ruby/#{ver}/#{plat}"
      #
      # optionally add paths to site_ruby libs
      # only apply if there are things installed there
      #$LOAD_PATH << "#{pre}/site_ruby/#{ver}"
      #$LOAD_PATH << "#{pre}/site_ruby/#{ver}/#{plat}"
      #
      $LOAD_PATH.uniq!
      #
      # print LOAD PATHS to console
      # (May not print during Sketchup startup!)
      Sketchup.send_action('showRubyPanel:')
      UI.start_timer(1,false) {
        puts "\nLOAD PATHS:\n"
        $LOAD_PATH.each {|x| puts "#{x}\n"}
        puts "\n\n"
      }
      #
    end
    # cleanup
    ver=nil
    pre=nil
    plat=nil
    GC.start
    #
    # end of '!loadpaths.rb'

このコードの出典は、以下の通りです。
http://sketchucation.com/forums/viewtopic.php?t=29412#p257058

著作権はパブリックドメインと書いてあります。
記事執筆時点(2012/12/13)で、v3.0.1です。
使用される方は、最新版を確認される事をおすすめします。

テスト環境:
OS X(10.8.2)
Rubyバージョン:1.9.3

satrex
usually on C#, can use VB, C++. studying javascript, ruby.
http://blog.satrex.jp
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away