Load wrap=true and adding methods to classes in the prog being called

S

Seb Clediere

Dear Rubyists,

foo.rb:
class String
def quote() "'"+self+"'" end
end

puts "blabla".quote
---

bar.rb:
load 'foo.rb', true
---

foo.rb executes ok,
bar.rb gives "undefined method `quote' for "blabla":String
(NoMethodError)" which I do understand since the script is now beeing
executed under an anonymous module.

Is there a way to still protect the namespace of the caller prog, but
not having this effect? (i.e. still being able in the called prog to add
methods to classes defined elsewhere, and whithout these methods
poluting the caller...)

Thanks very much!

Seb.
 
T

ts

S> Is there a way to still protect the namespace of the caller prog, but
S> not having this effect? (i.e. still being able in the called prog to add
S> methods to classes defined elsewhere, and whithout these methods
S> poluting the caller...)

See the module import_module, ruby_behaviors ... in RAA


Guy Decoux
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top