2. What is Ruby?
• Ruby is a dynamic, reflective, general-
purpose object-oriented programming
language...
• A dynamic, open source programming
language with a focus on simplicity and
productivity.
3. class Person
def say something
puts something
end
end
# Create a person object
ryan = Person.new
# Have Ryan say hello!
ryan.say 'Hello there!'
4. Want to play along?
Mac Open Terminal.app
Window Do a thing?
Web http://tryruby.org
13. Strings and Integers
name = 'Ryan'
# Comparing numbers (in a hash, by the way)
hours[:xbox] = 473
hours[:worked] = 3
14. Strings and Integers
name = 'Ryan'
# Comparing numbers (in a hash, by the way)
hours[:xbox] = 473
hours[:worked] = 3
hours[:xbox] > hours[:worked]
15. Strings and Integers
name = 'Ryan'
# Comparing numbers (in a hash, by the way)
hours[:xbox] = 473
hours[:worked] = 3
hours[:xbox] > hours[:worked]
=> true
20. Ranges
beers = (2..10)
beers.each do |count|
puts case count
when 2..3 then "#{count} beers? No problem!"
when 4..7 then "Approaching dangerous territory."
when 8..10 then "Seriously?? #{count} beers?"
end
end
=> 2 beers? No problem!
=> 3 beers? No problem!
=> Approaching dangerous territory.
=> ...
23. Control Structures
if condition case myvar
# do something when foo then "Hello!"
elsif condition when baz then "Good bye"
# do something end
else
# do something
end
24. Control Structures
if condition case myvar
# do something when foo then "Hello!"
elsif condition when baz then "Good bye"
# do something end
else
# do something while condition
end # do something
end