Nesta palestra passaremos uma breve introdução a Ruby e apresentarei como o Ruby on Rails favorece a produtividade no desenvolvimento de aplicações Web.
5. "Programmers should
always be interested in
learning new languages,
preferably from an
unfamiliar paradigm"
"97Things Every Programmer Should Know"
segunda-feira, 29 de abril de 13
16. Tudo é objeto
10.times{ |n| puts n }
10.class
=> Fixnum
Fixnum.class
=> Class
segunda-feira, 29 de abril de 13
17. Tudo é objeto
10.times{ |n| puts n }
10.class
=> Fixnum
Fixnum.class
=> Class
Fixnum.ancestors
=> [Fixnum, Integer, Numeric,
Comparable, Object, Kernel,
BasicObject]
segunda-feira, 29 de abril de 13
18. # This
1 + 2
# Is the same as this ...
1.+(2)
# Which is the same as this:
1.send "+", 2
segunda-feira, 29 de abril de 13
19. # This
1 + 2
# Is the same as this ...
1.+(2)
# Which is the same as this:
1.send "+", 2
segunda-feira, 29 de abril de 13
23. class Car
def inspect
“Cheap car”
end
end
other_car = Car.new
other_car.inspect # => “Cheap car”
segunda-feira, 29 de abril de 13
24. class Car
def inspect
“Cheap car”
end
end
other_car = Car.new
other_car.inspect # => “Cheap car”
segunda-feira, 29 de abril de 13
25. class Car
def inspect
“Cheap car”
end
end
porsche = Car.new
porsche.inspect # => “Cheap car”
def porsche.inspect
“Expensive car”
end
porsche.inspect # => “Expensive car”
other_car = Car.new
other_car.inspect # => “Cheap car”
segunda-feira, 29 de abril de 13
26. class Car
def inspect
“Cheap car”
end
end
porsche = Car.new
porsche.inspect # => “Cheap car”
def porsche.inspect
“Expensive car”
end
porsche.inspect # => “Expensive car”
other_car = Car.new
other_car.inspect # => “Cheap car”
segunda-feira, 29 de abril de 13
27. class Fixnum
def hours
self * 3600 # number of seconds/hour
end
alias hour hours
end
# 14 hours from 00:00 January 1st
Time.mktime(2006, 01, 01) + 14.hours
# => Sun Jan 01 14:00:00
segunda-feira, 29 de abril de 13
28. class Fixnum
def hours
self * 3600 # number of seconds/hour
end
alias hour hours
end
# 14 hours from 00:00 January 1st
Time.mktime(2006, 01, 01) + 14.hours
# => Sun Jan 01 14:00:00
Time.mktime(2006, 01, 01) + 14.hours
# => Sun Jan 01 14:00:00
segunda-feira, 29 de abril de 13
29. class Fixnum
def hours
self * 3600 # number of seconds/hour
end
alias hour hours
end
# 14 hours from 00:00 January 1st
Time.mktime(2006, 01, 01) + 14.hours
# => Sun Jan 01 14:00:00
Time.mktime(2006, 01, 01) + 14.hours
# => Sun Jan 01 14:00:00
segunda-feira, 29 de abril de 13
30. Time.now + 2.days
# => 2013-05-01 12:40:57 -0300
#Rails
segunda-feira, 29 de abril de 13
31. Time.now + 2.days
# => 2013-05-01 12:40:57 -0300
#Rails
segunda-feira, 29 de abril de 13
53. Model - Scope
@published = Post.where(published: true)
class Post < ActiveRecord::Base
scope :published, where(published: true)
end
segunda-feira, 29 de abril de 13
54. Model - Scope
@published = Post.where(published: true)
class Post < ActiveRecord::Base
scope :published, where(published: true)
end
@published = Post.published
segunda-feira, 29 de abril de 13
59. Migrations
Migrations are a convenient way for you to
alter your database in a structured and
organized manner
segunda-feira, 29 de abril de 13
60. class CreateProducts < ActiveRecord::Migration
def up
create_table :products do |t|
t.string :name
t.text :description
t.timestamps
end
end
def down
drop_table :products
end
end
segunda-feira, 29 de abril de 13