You are not logged in.
Pages: 1
Trying to learn Ruby but when developing simple apps I am spending more time searching basic Ruby commands in Internet than doing the work. In Internet Ruby documenations are either too newbie or advance and very few samples.
To get the basic Ruby what commonly used in developing, here is list of Bash syntax I would like to have an equal Ruby.
Example.
# Bash
if [ -f "file.txt" ]; then
else
if
# Ruby:
if(FileTest.exists? "file.txt")
else
List of Bash syntax:
cat file.txt
grep "hello" file.txt
sed 's/hello/hello world/g' file.txt
awk '{ print $2 }' file.txt
echo "hello" > file.txt
echo "world" >> file.txt
Markku
Offline
A good start. Quick reference..
http://www.zenspider.com/Languages/Ruby/QuickRef.html
Good examples
http://pleac.sourceforge.net/pleac_ruby/index.html
Ruby Language docs.
http://www.ruby-doc.org/core/
http://www.ruby-doc.org/stdlib/
I will do one for ya.
Bash: cat file.txt
Ruby:
puts IO.read("testfile")
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
# grep "hello" file.txt
puts IO.read('file.txt').grep(/hello/)
# sed 's/hello/hello world/g' file.txt
puts IO.read('file.txt').gsub('hello','hello world')
# awk '{ print $2 }' file.txt
puts IO.readlines('file.txt').map{ |r| r.split[1] }
# echo "hello" > file.txt
File.open('file.txt','w'){ |f| f.puts "hello" }
# echo "world" >> file.txt
File.open('file.txt','a'){ |f| f.puts "world" }
Offline
Thanks guys for the input.
I am setting up a Ruby and Glade page.
http://user-contributions.org/wikis/use … y-Libglade
For your information this what I am working on:
http://user-contributions.org/projects/ … kginfo.jpg
Markku
Offline
# grep "hello" file.txt puts IO.read('file.txt').grep(/hello/)
How to grep a variable? In ".grep(/hello/)" cannot use a variable.
# grep $var file.txt
Markku
Offline
Thanks.
This what I got from an other forum.
puts IO.read('file.txt').grep(/#{$var}/
Setting up a Bash to Ruby page:
http://user-contributions.org/wikis/use … sh-to-Ruby
Markku
Offline
Pages: 1