each

ios.each(sep=$/) {|line| block } â ios
ios.each(limit) {|line| block } â ios
ios.each(sep,limit) {|line| block } â ios
ios.each(...) â an_enumerator
ios.each_line(sep=$/) {|line| block } â ios
ios.each_line(limit) {|line| block } â ios
ios.each_line(sep,limit) {|line| block } â ios
ios.each_line(...) â an_enumerator
Instance Public methods

Executes the block for every line in ios, where lines are separated by sep. ios must be opened for reading or an IOError will be raised.

If no block is given, an enumerator is returned instead.

f = File.new("testfile")
f.each {|line| puts "#{f.lineno}: #{line}" }

produces:

1: This is line one
2: This is line two
3: This is line three
4: And so on...
doc_ruby_on_rails
2015-04-13 10:53:55
Comments
Leave a Comment

Please login to continue.