From: Jos Backus Date: 2007-01-19T08:53:56+09:00 Subject: Scoping and locating definitions Consider the following: lizzy:~% cat r require 'lib' # from 'lib' import 'Foo' f = Foo.new("string") p f.bar p 'abc'.rot13 lizzy:~% cat lib.rb class String def rot13 tr 'A-Za-z', 'N-ZA-Mn-za-m' end end class Foo def initialize(s) @s = s end def bar @s.rot13 end end lizzy:~% ruby r "fgevat" "nop" lizzy:~% What if I wanted String#rot13 to _not_ be visible in file `r' (because I didn't ask for it)? How do I contain the change to String to lib.rb only? Or perhaps to Foo? (The idea is to be able to reduce side-effects from require'ing files. Python forces one to be explicit about this, and that seems like a Good Thing.) On a related note: how does one go about finding _where_ String#rot13 was defined? One possible way would be for .methods to return an Array of BoundMethods instead of Strings and have file and linenumber information be part of BoundMethod (if possible). Thoughts? -- Jos Backus jos at catnook.com