From: Michael Geary Date: 2004-07-04T17:42:43+09:00 Subject: Re: Beginner question Mikael Larsson wrote: > > class String > def rot13 > self.tr!("A-Ma-mN-Zn-z", "N-Zn-zA-Ma-m") > end > end > > str = "Micke" > > puts "#{str} become #{str.rot13()}" #Micke become Zvpxr > puts "#{str} become #{str.rot13()}" #Zvpxr become Micke > puts "#{str} become #{str.swapcase()}" #Micke become mICKE > > For me looks like we are doing some implicit inherence here, like this: > class String < String > def rot13 > self.tr!("A-Ma-mN-Zn-z", "N-Zn-zA-Ma-m") > end > end > > Dose any one have a good explanation? What you're seeing is the fact that you can reopen a class and add new methods to it at any time. Your String class doesn't inherit from the original String class; it *is* the original String class. You're adding a new method to that class. Try this example for comparison: ### class Test def a 123 end end test = Test.new p test.a class Test def b a end end p test.a p test.b ### -Mike