open-uri and Kernel.open

S

Scott

I am new ruby usrs (and loving it) and have a question.

By "requiring" opne-uri into my source file I can now reference "http"
addresses as they were local files. It seems that open-uri "hooks"
into the Kernel.open method.

I am just wondering what aspect of the ruby language allows you to do
this. Or is there some mechanism inside of the Kernel that allows you
to register a different protocol?

thanks in advance, scott.
 
M

Mohit Muthanna

The open-uri module simply redefines the Kernel.open method. You can
do it yourself:

module Kernel
private
alias original_open open

def open( blah, *blah_params, &blah_block)
...blah
if some_condition
original_open( blah, *blah_params, &blah_block)
end
end

module_function :eek:pen
end


Above, we store the original "open" method in original_open; then we
redefine open, calling the original open function if necessary.

HTH,
Mohit.


I am new ruby usrs (and loving it) and have a question.
=20
By "requiring" opne-uri into my source file I can now reference "http"
addresses as they were local files. It seems that open-uri "hooks"
into the Kernel.open method.
=20
I am just wondering what aspect of the ruby language allows you to do
this. Or is there some mechanism inside of the Kernel that allows you
to register a different protocol?
=20
thanks in advance, scott.
=20
=20
=20


--=20
Mohit Muthanna [mohit (at) muthanna (uhuh) com]
"There are 10 types of people. Those who understand binary, and those
who don't."
 
S

Scott

Thanks for the info. Thats a cool feature of Ruby where you can
redfine existing methods.
 
R

Robert Klemme

Scott said:
Thanks for the info. Thats a cool feature of Ruby where you can
redfine existing methods.

One of the most widely used features... :)

Btw, you don't need this line:

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top