Ruby IRB - Can't do Process.getrlimit - ruby

I am reading a book "Working with Unix Processes" which uses ruby to explain about unix/linux processes. This is my first time working with ruby. I tried an example to get resource limits on processes.
irb(main):001:0> Process.getrlimit(:CORE)
Errno::EINVAL: Invalid argument - getrlimit
from (irb):1:in `getrlimit'
from (irb):1
from :0
irb(main):004:0> Process.getrlimit()
ArgumentError: wrong number of arguments (0 for 1)
from (irb):4:in `getrlimit'
from (irb):4
from :0
But I can't seem to get "getrlimit" recognized (though it says I have wrong number of arguments if I don't supply any args). Haven't found anything on this on google or SO. Tried with :NOFILE, :CORE and others. Is there something I need to include/require to make getrlimit work. Environment:
Ubuntu 11.04 32 bit. Kernel 3.0.0-14
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
irb 0.9.5(05/04/13)
regards

Sorry .. never mind. It seems that IRB was running a previous version of ruby (1.8.7) which somehow didn't support the getrlimit (though according to all accounts on google, it should have worked). I had upgraded ruby to 1.9.1 but did not update the link from /usr/bin/irb to /usr/bin/irb1.9.1. So IRB was still running ruby 1.8.7. After updating the softlink of irb to v1.9.1, getrlimit is now working.

Related

What are the GEM_DEP_FILES entries in rubygems?

I have been trying to learn more about the rubygems system in ruby. One curious constant I have encountered is GEM_DEP_FILES. The ruby-doc.org page for Module: Gem has nothing to say about this value other than its name. Here is what I get in irb:
irb(main):002:0> Gem::GEM_DEP_FILES
=> ["gem.deps.rb", "Gemfile", "Isolate"]
Now "Gemfile" is the dependency mechanism we all know and love. I think; At least it is the same name.
My question is what about the others?
A wild guess is that "gem.deps.rb" is some old, obsolete predecessor to "Gemfile"? Maybe?
I have no clue at all about the entry called "Isolate".
I have looked with no success. Can anyone shed any light about these obscure entries?
In case it matters:
20 mysh>ruby --version
ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
21 mysh>gem --version
2.5.2
http://ruby-doc.org/stdlib-2.3.3/libdoc/rubygems/rdoc/Gem.html
I am working to add a utility command to my mysh program that will display pertinent gem related info, so any info, advice, or guidance would be most welcome.

Ruby not finding rubygems or wx modules

I'm running the default Ruby installation (ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10]) on my Intel iMac. I updated RubyGems and installed the wxruby gem. I'm trying to run the following sample program:
#!/usr/bin/ruby
require "rubygems"
require "wx"
class MyApp < Wx::App
def on_init
#frame = Wx::Frame.new(nil, -1, "The Bare Minimum")
#frame.show()
end
end
app = MyApp.new()
app.main_loop()
And I get the following error:
==> wxruby-test.rb
/Library/Ruby/Gems/1.8/gems/wxruby-1.9.3-universal-darwin/lib/wxruby2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/wxruby-1.9.3-universal-darwin/lib/wxruby2.bundle, 9): no suitable image found. Did find: (LoadError)
/Library/Ruby/Gems/1.8/gems/wxruby-1.9.3-universal-darwin/lib/wxruby2.bundle: no matching architecture in universal wrapper - /Library/Ruby/Gems/1.8/gems/wxruby-1.9.3-universal-darwin/lib/wxruby2.bundle
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require'
from /Library/Ruby/Gems/1.8/gems/wxruby-1.9.3-universal-darwin/lib/wx.rb:12
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:60:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:60:in `require'
from wxruby-test.rb:3
If I comment out the require rubygems statement, I get the following error:
==> wxruby-test.rb
wxruby-test.rb:3:in `require': no such file to load -- wx (LoadError)
from wxruby-test.rb:3
I'm new to Ruby on the Mac, and I'm sure this is some basic error probably related to paths, but most explanations about the environment variables are aimed at experienced users. If you need more output from other commands, please let me know. I'm running Ruby from the tcsh shell. I'm sure I'm doing something basic wrong, but I'm just stumped.
If you're running Ruby 1.8.7 you should leave in the require statement:
require "rubygems"
Ruby 1.8 didn't know about gems by default, so we had to tell Ruby to require the gems loader. Ruby 1.9+ bundles it so we no longer have to do the require.
This has nothing to do with the Mac (or Windows or Linux) OS, it's about Ruby's default load paths.
And, as a safety tip, don't mess with Ruby installed by Apple. They installed it for their own use, and it's used for some podcast-creation tools. And, at some future point they might want to add something to the system that takes advantage of an expected configuration of Ruby (or Python or Perl). Changing (or worse, deleting it) can mess you up. So, I recommend you leave it alone and use either rbenv or RVM to install Ruby in a sandbox, where you can poke, prod and mess with it safely.
What version of OS X? If it's one of the Lions, then you're out of luck. The wxwidgets library (and things based on it, like wxruby) is still only 32-bit and based on Carbon. The Lions are 64-bit-only and Carbon is deprecated.

Rails 3 continues to use ruby 1.8.7 even though "ruby -v" states 1.9.2

I have finished developing my app and am currently deploying it. I'm getting a weird error from one of my controllers:
syntax error, unexpected ':', expecting ')'
When I run it in my dev environment it works fine. The only difference I can see between dev/prod is that dev is is using Ruby 1.9.2 and Prod is using 1.8.7. In my naivete I thought "Oh I'll just upgrade to 1.9.2" - what I fool I've been. I used RVM, changed my path, started new terminal session and now can see ruby is at 1.9.2:
ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
which ruby
/usr/local/rvm/rubies/ruby-1.9.2-p290/bin/ruby
However, when I run a "rails s" my computer continues to use 1.8.7:
[2011-10-05 05:58:40] INFO WEBrick 1.3.1
[2011-10-05 05:58:40] INFO ruby 1.8.7 (2010-08-16) [x86_64-linux]
[2011-10-05 05:58:45] INFO WEBrick::HTTPServer#start: pid=32574 port=3000
What the what!!!? I hope someone can help me. I'm about 15 minutes away from moving to the country, and become a farmer!
Thanks in advance.
if you used sudo when installed it might be the reason
sudo passenger-install-apache2-module
uses system ruby. Try
passenger-install-apache2-module
which should produce proper config files.
Have you tried rvm reload ? sometimes when I get strange errors like that reloading rvm fixes it.

Segmentation Fault in rvm'd Ruby on Mac when running RSpec

I was developing something at the uni, saved to my Dropbox intending to continue at home. This is the message that greeted me:
$ spec graph_spec.rb
/Users/amadan/.rvm/gems/ruby-1.9.2-rc1/gems/PriorityQueue-0.1.2/ext/priority_queue/CPriorityQueue.bundle: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
However,
$ `which spec` graph_spec.rb
...........................................................................
Finished in 0.046973 seconds
75 examples, 0 failures
What the heck is going on here?
For the reference:
$ which spec
/Users/amadan/.rvm/gems/ruby-1.9.2-rc1/bin/spec
UPDATE: I just noticed the 1.8.7 there... how did it get there? The top of the spec file says:
$ head `which spec`
#!/Users/amadan/.rvm/rubies/ruby-1.9.2-rc1/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
Where does it say "run 1.8.7"?!?
It's likely that RVM is messing your gems and rubies. I would recommend testing on a cleaned up RVM installation (with only 1.9 installed).
Is /Users/amadan/.rvm/rubies/ruby-1.9.2-rc1/bin/rubyreally ruby 1.9.2 ?
Other way to test would be to explicitely run ruby spec so you are sure this is really 1.9.2 which is called.
To conclude, Segfaults do happen in ruby (esp. on 1.8) and are sometimes avoided by reorganizing slightly the ruby code. Good Luck !

How can I get rid of this ruby warning?

I have just installed ruby 1.9.1-p429 with macports. Every time I use it, it displays this error message:
$ ruby1.9 -e "puts 'hi.'"
Error loading gem paths on load path in gem_prelude
can't modify frozen string
<internal:gem_prelude>:69:in `force_encoding'
<internal:gem_prelude>:69:in `set_home'
<internal:gem_prelude>:38:in `dir'
<internal:gem_prelude>:76:in `set_paths'
<internal:gem_prelude>:47:in `path'
<internal:gem_prelude>:286:in `push_all_highest_version_gems_on_load_path'
<internal:gem_prelude>:355:in `<compiled>'
hi.
It's a bug: see bug report here
I don't know if either is available from MacPorts, but Ruby 1.9.1-p378 and 1.9.2-rc1 are both free of the problem.
If you haven't already tried it, I highly recommend rvm for multiple Ruby interpreters.

Resources