Next 3.3 String methods Prev

String methods

String is one of the largest built-in Ruby class, with over 80 standard methods.
File.open("/etc/passwd") { |file|
   file.each { |line|
      uname, crypt, uid, gid, name, shell = line.chomp.split(':')
      printf "%3d #{uname}\n", uid
   }
}
  0 root
  1 bin
  2 daemon
 99 nobody
500 migo
501 eilara

Work-on-copy vus in-place methods:
(myString = "  I love Perl\n").chomp!.chomp!("Perl").strip!
p myString += " Ruby\n"

"I love Ruby\n"
 

Next Ruby for Perl programmers Prev