making ex20 more ruby-ish
This commit is contained in:
parent
a9ac349ba9
commit
aa308911d4
10
ex20.rb
10
ex20.rb
@ -1,7 +1,7 @@
|
|||||||
input_file = ARGV[0]
|
input_file = ARGV.first
|
||||||
|
|
||||||
def print_all(f)
|
def print_all(f)
|
||||||
puts f.read()
|
puts f.read
|
||||||
end
|
end
|
||||||
|
|
||||||
def rewind(f)
|
def rewind(f)
|
||||||
@ -9,7 +9,7 @@ def rewind(f)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def print_a_line(line_count, f)
|
def print_a_line(line_count, f)
|
||||||
puts "#{line_count} #{f.readline()}"
|
puts "#{line_count} #{f.readline}"
|
||||||
end
|
end
|
||||||
|
|
||||||
current_file = File.open(input_file)
|
current_file = File.open(input_file)
|
||||||
@ -28,8 +28,8 @@ puts "Let's print three lines:"
|
|||||||
current_line = 1
|
current_line = 1
|
||||||
print_a_line(current_line, current_file)
|
print_a_line(current_line, current_file)
|
||||||
|
|
||||||
current_line = current_line + 1
|
current_line += 1
|
||||||
print_a_line(current_line, current_file)
|
print_a_line(current_line, current_file)
|
||||||
|
|
||||||
current_line = current_line + 1
|
current_line += 1
|
||||||
print_a_line(current_line, current_file)
|
print_a_line(current_line, current_file)
|
||||||
|
Loading…
Reference in New Issue
Block a user