lib/rio/doc/HOWTO.rb in rio-0.3.3 vs lib/rio/doc/HOWTO.rb in rio-0.3.4
- old
+ new
@@ -51,19 +51,19 @@
string = ""
array = []
* Read a file into a string.
# method 1
- string = ario.slurp
+ string = ario.contents
# method 2
ario > string
* Append a file onto a string.
# method 1
ario >> string
# method 2
- string += ario.slurp
+ string += ario.contents
* Read lines of a file into an array
# method 1
array = ario[]
# method 2
@@ -109,17 +109,17 @@
* Read a gzipped file into a string
# method 1
rio('afile.gz').gzip > string
# method 2
- string = rio('afile.gz').gzip.slurp
+ string = rio('afile.gz').gzip.contents
* Append a gzipped file into a string
# method 1
rio('afile.gz').gzip >> string
# method 2
- string += rio('afile.gz').gzip.slurp
+ string += rio('afile.gz').gzip.contents
* Iterate through all the lines of a file
# method 1
rio('afile').lines { |line| ... }
# method 2
@@ -130,21 +130,21 @@
* Iterate through the lines of a gzipped file
rio('afile.gz').gzip { |line| ... }
* Iterate through all non-empty lines of a gzipped file, with each line chomped
- rio('afile.gz').gzip.chomp.nolines(:empty?) { |line| ... }
+ rio('afile.gz').gzip.chomp.skiplines(:empty?) { |line| ... }
* Iterate through the first 100 lines of a file
# method 1
rio('afile').lines(0...100) { |line| ... }
* Iterate through the first line and all ruby comment lines in a gzipped file
rio('afile.rb.gz').gzip.lines(0,/^\s*#/) { |line| ... }
* Iterate through the lines of a ruby file that are neither empty nor comments, with all lines chomped
- rio('afile.rb.gz').chomp.nolines(/^\s*#/,:empty?) { |line| ... }
+ rio('afile.rb.gz').chomp.skiplines(/^\s*#/,:empty?) { |line| ... }
* Read all the comment lines from a ruby file into an array with all lines chomped
# method 1
array = rio('afile.rb').chomp.lines[/^\s*#/]
# method 2
@@ -153,11 +153,11 @@
* Read lines of a file into an array, with each line chomped, skipping any lines longer than 1024 chars
# method 1
ario.chomp.lines(proc{ |line| line.length <= 1024}) > array
# method 2
- array = ario.chomp.nolines[proc{ |line| line.length > 1024}]
+ array = ario.chomp.skiplines[proc{ |line| line.length > 1024}]
# method 3
array = ario.chomp.lines(proc{ |line| line.length <= 1024}).to_a
---
@@ -238,25 +238,25 @@
# method 1
array = ario[proc{ |l| l.length > 128}]
# method 2
array = ario.lines[proc{ |l| l.length > 128}]
# method 3
- array = ario.nolines[proc{ |l| l.length <= 128}]
+ array = ario.skiplines[proc{ |l| l.length <= 128}]
* Copy all lines that do not start with 'zippy' into another file
# method 1
- ario.nolines(/^zippy/) > rio('another_file')
+ ario.skiplines(/^zippy/) > rio('another_file')
# method 2
- ario.lines.nolines(/^zippy/) > rio('another_file')
+ ario.lines.skiplines(/^zippy/) > rio('another_file')
# method 3
- rio('another_file') < ario.nolines(/^zippy/)
+ rio('another_file') < ario.skiplines(/^zippy/)
* Copy the first 10 lines and lines starting with 'zippy', but exclude any lines longer than 128 bytes
# method 1
- ario.lines(0...10,/^zippy/).nolines(proc{ |l| l.length > 128}] > rio('another_file')
+ ario.lines(0...10,/^zippy/).skiplines(proc{ |l| l.length > 128}] > rio('another_file')
# method 2
- rio('another_file') < ario.lines(0...10,/^zippy/).nolines(proc{ |l| l.length > 128})
+ rio('another_file') < ario.lines(0...10,/^zippy/).skiplines(proc{ |l| l.length > 128})
---
@@ -311,41 +311,41 @@
is_ruby_exe = proc{ |f| f.executable? and f.gets =~ /^#!.+ruby/ }
ario.norecurse('.svn','pkg').files('*.rb',is_ruby_exe) { |f| ... }
* Put all files excluding those that are symlinks to files in an array
# method 1
- array = ario.nofiles[:symlink?]
+ array = ario.skipfiles[:symlink?]
# method 2
- array = ario.nofiles(:symlink?).files[]
+ array = ario.skipfiles(:symlink?).files[]
# method 3
- array = ario.nofiles(:symlink?).to_a
+ array = ario.skipfiles(:symlink?).to_a
# method 4
- array = ario.files.nofiles[:symlink?]
+ array = ario.files.skipfiles[:symlink?]
* Put all entries that are not files (or symlinks to files) into an array
# method 1
- array = ario.nofiles[]
+ array = ario.skipfiles[]
# method 2
- array = ario.nofiles.to_a
+ array = ario.skipfiles.to_a
* Put all entries that are symlinks to files into an array
# method 1
array = ario.files[proc{|f| f.file? and f.symlink?}]
# method 2
array = ario.files(proc{|f| f.file? and f.symlink?}).to_a
* Put all directories except those named '.svn' into an array
# method 1
- array = ario.nodirs['.svn']
+ array = ario.skipdirs['.svn']
# method 2
- array = ario.nodirs[/^\.svn/]
+ array = ario.skipdirs[/^\.svn/]
# method 3
- array = ario.nodirs('.svn').to_a
+ array = ario.skipdirs('.svn').to_a
# method 4
- array = ario.nodirs('.svn').dirs[]
+ array = ario.skipdirs('.svn').dirs[]
# method 5
- array = ario.nodirs('.svn')[]
+ array = ario.skipdirs('.svn')[]
---
=== Read and writing files
@@ -357,19 +357,19 @@
# method 1
rio('srcfile') > rio('dstfile')
# method 2
rio('dstfile') < rio('srcfile')
# method 3
- rip('dstfile').print!(rio('srcfile').slurp)
+ rip('dstfile').print!(rio('srcfile').contents)
* Append the contents of one file to another file
# method 1
rio('srcfile') >> rio('dstfile')
# method 2
rio('dstfile') << rio('srcfile')
# method 3
- rip('dstfile').a.print!(rio('srcfile').slurp)
+ rip('dstfile').a.print!(rio('srcfile').contents)
* Copy the first 10 lines of one file to another file
# method 1
rio('srcfile').lines(0...10) > rio('dstfile')
# method 2
@@ -387,11 +387,11 @@
# method 1
rio('http://ruby-doc.org/') > rio('afile')
# method 2
rio('afile') < rio('http://ruby-doc.org/')
# method 3
- rio('afile').print!(rio('http://ruby-doc.org/').slurp)
+ rio('afile').print!(rio('http://ruby-doc.org/').contents)
* Append the output of the daytime server running on the localhost to a file
# method 1
rio("tcp://localhost:daytime") >> rio('afile')
# method 2
@@ -414,19 +414,19 @@
# method 1
rio('afile') > rio('afile.gz').gzip
# method 2
rio('afile.gz').gzip < rio('afile')
# method 3
- rio('afile.gz').gzip.print!( rio('afile').slurp )
+ rio('afile.gz').gzip.print!( rio('afile').contents )
* Create an ungzipped copy of a gzipped file
# method 1
rio('afile') < rio('afile.gz').gzip
# method 2
rio('afile.gz').gzip > rio('afile')
# method 3
- rio('afile').print!( rio('afile.gz').gzip.slurp )
+ rio('afile').print!( rio('afile.gz').gzip.contents )
* Copy the first 100 lines of gzipped file on a webserver into a local file
# method 1
rio('http://aserver/afile.gz').gzip.lines(0...100) > rio('afile')
@@ -446,13 +446,13 @@
string = ""
array = []
* Count the lines of code in a directory tree of ruby source files
# method 1
- cnt = ario.all.files('*.rb').chomp.nolines(/^\s*#/,/^\s*$/).inject(0) { |sum,l| sum += 1 }
+ cnt = ario.all.files('*.rb').chomp.skiplines(/^\s*#/,/^\s*$/).inject(0) { |sum,l| sum += 1 }
# method 2
- cnt = ario.all.files('*.rb').chomp.nolines[/^\s*#/,/^\s*$/].size
+ cnt = ario.all.files('*.rb').chomp.skiplines[/^\s*#/,/^\s*$/].size
* Concatanate the contents of all .txt files in a directory into an array
# method 1
array = ario.lines.files['*.txt']
# method 2
@@ -546,11 +546,11 @@
# method 3
rio('afile') > rio(?-)
# method 4
rio(?-) < rio('afile')
# method 5
- rio(?-).print(rio('afile').slurp)
+ rio(?-).print(rio('afile').contents)
* Emulate a simplified unix 'head' command which reads from stdin and writes the first 10 lines to stdout
# method 1
rio(?-).lines(0..9) > rio(?-)
@@ -558,10 +558,10 @@
=== Reading and writing from processes as one might do with popen
* Read the output of the 'ps' command into an array without the header line or the line representing
the 'ps' command itself
- ps = rio(?-,'ps -a').nolines[0,/ps$/]
+ ps = rio(?-,'ps -a').skiplines[0,/ps$/]
* Run an external program, copying its input from one location and its output from another,
and make it look very much like a shell command.
# method 1
ans = ""