5
Learning Ruby - 5 Files

Learning Ruby - 5 Files. while line = gets puts line end while line = gets puts line.downcase end while line = gets puts line.downcase if line =~ /UP

  • View
    214

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Learning Ruby - 5 Files. while line = gets puts line end while line = gets puts line.downcase end while line = gets puts line.downcase if line =~ /UP

Learning Ruby - 5

Files

Page 2: Learning Ruby - 5 Files. while line = gets puts line end while line = gets puts line.downcase end while line = gets puts line.downcase if line =~ /UP

while line = getsputs line

end

while line = getsputs line.downcase

end

while line = getsputs line.downcase if line =~ /UP/

end

The "readlines" Program x 3

Page 3: Learning Ruby - 5 Files. while line = gets puts line end while line = gets puts line.downcase end while line = gets puts line.downcase if line =~ /UP

File.open( "/etc/passwd" ) do |my_file| my_file.each_byte do |byte|

putc byte; print "." end # of do.

end # of do.

File.open( "/etc/passwd" ) do |my_file| my_file.each_line { |line| puts line }

end # of do.

IO.foreach( "/etc/passwd" ) { |line| puts line }

File Reading Iterators

Page 4: Learning Ruby - 5 Files. while line = gets puts line end while line = gets puts line.downcase end while line = gets puts line.downcase if line =~ /UP

print STDOUT << "Hello" << " " << "World!" << "\n"

Ruby's a bit like C++ - Yuk!

Page 5: Learning Ruby - 5 Files. while line = gets puts line end while line = gets puts line.downcase end while line = gets puts line.downcase if line =~ /UP

More ... Ruby So Far

Files are easy to work with in Ruby

Take advantage of the in-built iterators and methods when working with files