M
Mikael Larsson
Hi
I wrote about Ruby a year ago, I find it intersting, so I bought "Hal
Fulton's" book "the Ruby way", but I haven'thad time to read it until now.
Tho book is really good, but the writer don't explain this construction (from
page 81) (or I haven't found the explanation):
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?
Regards,
Mike
I wrote about Ruby a year ago, I find it intersting, so I bought "Hal
Fulton's" book "the Ruby way", but I haven'thad time to read it until now.
Tho book is really good, but the writer don't explain this construction (from
page 81) (or I haven't found the explanation):
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?
Regards,
Mike