Title: A Programming Language for Lazy People
1(No Transcript)
2A Programming Language for Lazy People
3String and Array Arithmetic
"foo" 3
"foofoofoo"
1,2,3 - 2,3
1
1,2,3 2,3
2,3
Open Webpage as File
require "open-uri" open("http//www.example.com/")
do page parse page and do stuff end
Sort Objects by Attributes
people.sort_by do p p.last_name,
p.first_name, p.middle_initial end
4Blocks Allow Powerful Constructs
5Blocks in Java
for(String s myStringArray)
System.out.printLine(s)
synchronized(dbHandler) // access database
In Ruby, Any Method Can Have a Block
1, 2, 3.each do i puts i 2 end
2 4 6
File.open(file.txt) do f f.each_line do
l puts line end end
6Generate Markup
markaby.html do head title "Boats.com"
body do h1 "Boats.com has great deals" ul
do li "49 for a canoe" li "39 for a
raft" end end end From Markaby
documentation
lthtmlgt ltheadgtlttitlegtBoats.comlt/titlegtlt/headgt
ltbodygt...lt/bodygt lt/htmlgt
7Dynamic Nothing is Final
8Open Classes
Class String def leet_speak self.sub(" e",
" 3") end End "Me likes ruby".leet_speak
"M3 lik3s ruby"
Test Assertions in English
require 'test/spec ... (2 3).should
5 ... my_method.should.not.raise
ConnectionError From Test/Unit documentation