Le jeu 05/12/2002 ? 11:54, Shannon Fang a ?crit :
> Hi
> 
> I tried String.methods-Kernel.methods in irb, found that most methods of 
> String are inherited from Kernel. I don't know for methods like sub, gsub, 
> split, strip, chomp... Are they String specific? Why they exist in Kernel?
> 
> Thanks!
> Shannon
Hi Shannon,

I try ti answer with my poor english ;)

kernet is a module include in the super class "Object", all the methods
of this module are usable in any point of your code.

String is a predefined class of the module kernel and is ancestor is the
super class "Object": it is an instance of the class "Object". 

This is the raison that you can use something like the predefined
variable $_ like this:

irb(main):014:0> $_ ="Hello, world!\n"
"Hello, world!\n"
irb(main):015:0> print $_
Hello, world!
nil
irb(main):016:0> $_ =  chop + " nice dayto play with ruby ;)"
"Hello, world! nice dayto play with ruby ;)"
irb(main):017:0> chop
"Hello, world! nice dayto play with ruby ;"
irb(main):018:0> 

Daniel

 
> 
> _________________________________________________________________
> STOP MORE SPAM with the new MSN 8 and get 2 months FREE* 
> http://join.msn.com/?page=features/junkmail
> 
> 
>