------art_45968_22548176.1220210787373
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hello, here's my solution for this quiz.

I have never put together a piece of metaprogramming that I would use
with confidence until this quiz ;-)

On 29/08/2008, Matthew Moss <matthew.moss / gmail.com> wrote:

>  What I would like is a script that works like `which` but for Ruby
>  modules. Examples:
>
>     > ruby modwhich.rb "sys/uptime"
>     require 'sys/uptime' >  /opt/local/lib/ruby/vendor_ruby/1.8/i686-darwin8.11.1/sys/uptime.bundle

This should work although the solution is not tested on a Mac.

>
>     > ruby modwhich.rb date
>     require 'date' /opt/local/lib/ruby/1.8/date.rb

This works.

>
>  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

This should also work within reason - modules loaded from files
located in rubylibdir are not printed.

Thanks

Michal

------art_45968_22548176.1220210787373
Content-Type: application/x-ruby; name=q175.rb
Content-Transfer-Encoding: base64
X-Attachment-Id: f_fkk1wxtu
Content-Disposition: attachment; filename=q175.rb

dW5sZXNzIEtlcm5lbC5jb25zdGFudHMuaW5jbHVkZT8gIlExNzUiCgpyZXF1aXJlICdyYmNvbmZp
ZycKCm1vZHVsZSBLZXJuZWwKCiAgbW9kdWxlIFExNzUKCiAgICBkZWYgc2VsZi5nZXRfZXh0cwog
ICAgICBleHRzID0gWyJyYiIsIENvbmZpZzo6Q09ORklHWyJETEVYVCJdLCBDb25maWc6OkNPTkZJ
R1siRExFWFQyIl1dCiAgICAgIGV4dHMucG9wIHVubGVzcyBleHRzWy0xXS5sZW5ndGggPiAwCiAg
ICAgIGV4dHMKICAgIGVuZAoKICAgIGRlZiBzZWxmLmRpcl9zZXBhcmF0b3I/IG51bQogICAgICB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