[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Seb Clediere

9/16/2003 11:18:00 AM

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.

1 Answer

ts

9/16/2003 12:05:00 PM

0

>>>>> "S" == Seb Clediere <Sebastien.Clediere@_nospam_laposte.net> writes:

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