SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
32.
Blocos
• Closures - Funções anônimas - Lambdas
• Sintaxe concisa (similar a Smalltalk)
• Duas sintaxes
do |a, b|
# código com a, b
end
{|a, b| # código com a, b }
33.
Blocos
do |a, b|
# código com a, b
end
{|a, b| # código com a, b }
34.
Blocos
obj.each do |e|
e.save!
end
(quot;aquot;..quot;zquot;).each do |char|
puts char
end
array.group_by {|a| a.type}
35.
Blocos
File.open(quot;config.txtquot;) do |in|
in.each_line do |line|
process_config_line(line)
end
end
(0..100).collect {|n| User.find(n).destroy }
53.
No Rails, você se preocupa mais
com a “Lógica de Negócio”
54.
No Rails, você se preocupa mais
com a “Lógica de Negócio”
55.
Classe Livro:
Pertence a um Autor
Tem várias Tags
Tem um Upload
O título tem no máximo 300 caracteres
Tem uma máquina de estados
56.
class Book < ActiveRecord::Base
# Relacionamentos
belongs_to :author
has_and_belongs_to_many :tags
has_one :upload
# Validação
validates_length_of :subtitle, :maximum => 300
57.
acts_as_state_machine :initial => :registred
state :passive
state :registred
state :waiting_processing
state :in_processing
state :preview
state :published
state :unpublished
event :register do
transitions :from => :passive, :to => :registred
end
# ...
end