M
Matthew Moss
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
The three rules of Ruby Quiz 2:
1. Please do not post any solutions or spoiler discussion for this
quiz until 48 hours have passed from the time on this message.
2. Support Ruby Quiz 2 by submitting ideas as often as you can! (A
permanent, new website is in the works for Ruby Quiz 2. Until then,
please visit the temporary website at
<http://splatbang.com/rubyquiz/>.
3. Enjoy!
Suggestion: A [QUIZ] in the subject of emails about the problem
helps everyone on Ruby Talk follow the discussion. Please reply to
the original quiz message, if you can.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Where the Required Things Are (#175)
Occasionally, I've taken a look at the source for some Ruby module,
often because there is no manual or man page, or what documentation is
available is outdated or incomplete. Or sometimes I just want to see
how some Ruby stuff is implemented.
One such example was from the previous quiz: I want to learn more
about the Sys::Uptime module. I have it installed, and the call to
`require 'sys/uptime'` works, but I don't know how to use it. But,
alas, I also don't know where the installed files are located. The
shell command `which` doesn't help here, since the module is unlikely
to be in the shell's executable path.
What I would like is a script that works like `which` but for Ruby
modules. Examples:
/opt/local/lib/ruby/vendor_ruby/1.8/i686-darwin8.11.1/sys/uptime.bundle
For extra credit, preserve this behavior when modwhich.rb is the main
program, but slightly different behavior is modwhich.rb is required by
another script:
require 'sys/uptime' =>
/opt/local/lib/ruby/vendor_ruby/1.8/i686-darwin8.11.1/sys/uptime.bundle
require 'date' => /opt/local/lib/ruby/1.8/date.rb
Last reboot: 2008 Aug 22 at 18:49
Note that we allow upsince.rb to run as normal; the output of
modwhich.rb is mixed into stdout.
The three rules of Ruby Quiz 2:
1. Please do not post any solutions or spoiler discussion for this
quiz until 48 hours have passed from the time on this message.
2. Support Ruby Quiz 2 by submitting ideas as often as you can! (A
permanent, new website is in the works for Ruby Quiz 2. Until then,
please visit the temporary website at
<http://splatbang.com/rubyquiz/>.
3. Enjoy!
Suggestion: A [QUIZ] in the subject of emails about the problem
helps everyone on Ruby Talk follow the discussion. Please reply to
the original quiz message, if you can.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Where the Required Things Are (#175)
Occasionally, I've taken a look at the source for some Ruby module,
often because there is no manual or man page, or what documentation is
available is outdated or incomplete. Or sometimes I just want to see
how some Ruby stuff is implemented.
One such example was from the previous quiz: I want to learn more
about the Sys::Uptime module. I have it installed, and the call to
`require 'sys/uptime'` works, but I don't know how to use it. But,
alas, I also don't know where the installed files are located. The
shell command `which` doesn't help here, since the module is unlikely
to be in the shell's executable path.
What I would like is a script that works like `which` but for Ruby
modules. Examples:
require 'sys/uptime' =>ruby modwhich.rb "sys/uptime"
/opt/local/lib/ruby/vendor_ruby/1.8/i686-darwin8.11.1/sys/uptime.bundle
require 'date' => /opt/local/lib/ruby/1.8/date.rbruby modwhich.rb date
For extra credit, preserve this behavior when modwhich.rb is the main
program, but slightly different behavior is modwhich.rb is required by
another script:
ruby -r modwhich upsince.rb
require 'sys/uptime' =>
/opt/local/lib/ruby/vendor_ruby/1.8/i686-darwin8.11.1/sys/uptime.bundle
require 'date' => /opt/local/lib/ruby/1.8/date.rb
Last reboot: 2008 Aug 22 at 18:49
Note that we allow upsince.rb to run as normal; the output of
modwhich.rb is mixed into stdout.