SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rubygems and paths

    I have installed the latest version of rubygems as root on an old Sun UltraSparc 2 running Solaris 8. I have successfully installed the latest progressbar gem as root. I have tried to implement a simple test of progressbar in the following script:

    #!/usr/local/bin/ruby

    require 'progressbar'

    $:.each {|a|
    puts a
    }

    bar = ProgressBar.new("Example progress", 50)
    total = 0
    until total >= 50
    ...sleep(rand(2)/2.0)
    ...increment = rand(6) + 3)
    ...bar.inc(increment)
    ...total += increment
    end

    Of course, I do not have leading periods in my script, but when I previewed this message it failed to indent those four lines, so I tried this as an aid to clarity.

    I have tried preceding the existing require line with require 'rubygems'. I have tried removing the #!/usr/local/bin/ruby and running ruby -rubygems progressbar. I have tried, as a c shell user, setenv RUBYOPT rubygems. In every case I get the identical response:

    /usr/local/lib/ruby/site_ruby/1.8
    /usr/local/lib/ruby/site_ruby/1.8/sparc-solaris2.8
    /usr/local/lib/ruby/site_ruby
    /usr/local/lib/ruby/1.8
    /usr/local/ruby/1.8/sparc-solaris2.8
    .
    ./progressbar.rb:9: unitialized constant ProgressBar (NameError)
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require__'
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
    from /home/ga155700/ruby/progressbar.rb:4

    I added the $: block in an attempt to trace my paths, but this shed no light, at least for me. Can someone explain what i am doing wrong?

    Thanks in advance - GGB

  2. #2
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ggb
    #!/usr/local/bin/ruby

    require 'progressbar'
    Changing this to:

    #!/usr/local/bin/ruby

    require 'rubygems'
    require_gem 'progressbar'

    did the trick!

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is still strange, I don't understand why it wouldn't search in the gem include folders by default...

    For other Rubyers out there, is the $: variable the one which holds all the include paths? If so, GGB you should check that out... to make sure its in there.
    Happy switcher to OS X running on a MacBook Pro.

    Zend Certified Engineer

  4. #4
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The "library stub" stuff was dropped in gems version 0.8. Now you have to require 'rubygems' before requiring specific gem.

  5. #5
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, what confused me was seeing instructions that claimed I just needed

    require 'progressbar'

    or

    require 'rubygems'
    require 'progressbar'

    It was not until I stumbled across the require_gem command that I finally got it to work. Sometimes it pays to spend an hour or two wading through the developers flamewars for a hint.

    Now when I run it with the $: block I also see

    /usr/local/lib/ruby/gems/1.8/gems/progressbar-0.0.3/lib

    which is the path I was originally hoping to see.

  6. #6
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stereofrog
    The "library stub" stuff was dropped in gems version 0.8. Now you have to require 'rubygems' before requiring specific gem.
    Ah, I see, thank you for letting me know.
    Happy switcher to OS X running on a MacBook Pro.

    Zend Certified Engineer


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •