Ruby
Allikas: Kuutõrvaja
Ruby see on imelihtne ehk lihtsaid käske-skripte ja muud vajalikku millega mängida ja midagi kokku klopsida. Ehk süntaksi õpe jms meenutused
Alustada võib ühe koleda lausega
puts "Hello, world!"
IO jaoks on hulk toredaid käske nagu..
gets, open, print, printf, putc, puts, readline, readlines
#!/usr/local/bin/ruby print "Enter your name: " name = gets
Jadatöötlus
ary = [1, 2, 3] puts ary[0]
cities = %w[ London
Oslo
Paris
Amsterdam
Berlin ]
visited = %w[Berlin Oslo]
puts "I still need " +
"to visit the " +
"following cities:",
cities - visited
Stringitöötlus
herb = "parsley" puts herb[0,1] puts herb[0..3]
Random funktsioon
puts rand(10)
saame suvalise numbri 0-10
for num in (0..100)
print num,"\n"
end
Lihtne tsükkel nullist sajani
topelt tsükkel
#!/usr/local/bin/ruby
1.upto(10) do |fg|
1.upto(10) do |bg|
print "1"
end
puts
end
Shelli värvid
puts " \e[32mROHELINE\e[0m"
värvitabel, asjalik-vajalik
[0, 1, 4, 5, 7].each do |attr|
puts '----------------------------------------------------------------'
puts "ESC[#{attr};Foreground;Background"
30.upto(37) do |fg|
40.upto(47) do |bg|
print "\033[#{attr};#{fg};#{bg}m #{fg};#{bg} "
end
puts "\033[0m"
end
end
#!/usr/bin/env ruby require 'pathname' Pathname.new($0).realpath()
#!/usr/bin/env ruby
ARGV.each do|a|
puts "Argument: #{a}"
end
./arg.sh ahaa Argument: ahaa
failid
File.open("file", "r") do |io|
# do something with io
end
File.open("/location/of/my/file.txt", "r") do |f|
while ! f.eof do
line = f.gets
puts line #Print the line to the screen
end
end
http://www.ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/index.html
http://www.elctech.com/articles/ruby-daemons-and-angels ruby ja deemonid
http://www.phptoruby.com/ php ja ruby süntaksi teisendused