class Ruby
def what?
"A dynamic, open source programming language " +
"with a focus on simplicity and productivity. " +
"It has an elegant syntax that is " +
"natural to read and easy to write."
end
end
Slide 3
Slide 3 text
class Ruby
def what_for?
{
web: ["Rails", "Sinatra", "Padrino"],
desktop: ["MacRuby", "IronRuby"],
mobile: ["RubyMotion", "MobiRuby", "Ruboto"]
}
end
end
# Collections
!
cities = %w[London Oslo Paris Amsterdam Berlin]
visited = %w[Berlin Oslo]
puts "I still need to visit: ", cities - visited
!
# >> I still need to visit:
# >> London
# >> Paris
# >> Amsterdam
# Variables
!
monster # is a local variable
!
Monster # is a constant
!
@monster # is an instance variable
!
@@monster # is a class variable
!
$monster # is a global variable
# Meta-programming
class Shape
attr_reader :dimensions
!
def initialize(dimensions = {})
@dimensions = dimensions
end
!
def width
dimensions[:width]
end
!
def height
dimensions[:height]
end
end
Slide 30
Slide 30 text
# Meta-programming
class Shape
attr_reader :dimensions
!
def initialize(dimensions = {})
@dimensions = dimensions
end
!
[:width, :height].each do |dim|
define_method(dim) do
dimensions[dim]
end
end
end