2009, ano do Ruby
 on Rails no Brasil
Cauê Guerra
caue.guerra@caelum.com.br

@caueguerra




 OndeTrabalhar.com
Ruby
Yukihiro Matsumoto (Matz)

“Often people, especially
computer engineers, focus on
the machines. But in fact we
need to focus on humans, on
how humans care about doing
programming or operating the
application of the machines. We
are the masters. They are the
slaves.”
Características
Características


Orientada a Objetos    2.times { puts “Olá” }
Características


Orientada a Objetos    2.times { puts “Olá” }


Tipagem dinâmica       @nome = “Cauê Guerra”
Características


Orientada a Objetos    2.times { puts “Olá” }


Tipagem dinâmica       @nome = “Cauê Guerra”


Meta-programação       Código que gera código
Características


Orientada a Objetos     2.times { puts “Olá” }


Tipagem dinâmica        @nome = “Cauê Guerra”


Meta-programação        Código que gera código


Programação funcional
Exemplo
Java

            class CalculadorDeMDC {
              public int calcula(int a, int b) {
                if (b == 0)
                  return a;
                else
                  return calcula(b, a % b);
              }
            }


CalculadorDeMDC calculador = new CalculadorDeMDC();
System.out.println(calculador.calcula(28, 7));
Scala

         class CalculadorDeMDC {
           def calcula(a: Int, b: Int): Int = {
             if (b == 0)
               a
             else
               calcula(b, a % b)
           }
         }


val calculador = new CalculadorDeMDC
println(calculador.calcula(28, 7))
Ruby
            class CalculadorDeMDC
             def calcula(a, b)
               if b == 0
                 a
               else
                 calcula(b, a % b)
               end
             end
            end

calculador = CalculadorDeMDC.new
puts calculador.calcula(28, 7)
Um outro exemplo
Java


public String[] paraMaiuscula(String[] palavras) {
  String[] resposta = new String[palavras.length];
  for (int i = 0; i < palavras.length; i++)
    resposta[i] = palavras[i].toUpperCase();
  return resposta;
}
Ruby



def paraMaiuscula(palavras)
 palavras.map { |palavra| palavra.upcase }
end
“Tornar as coisas
 simples, fáceis;
 e as complexas,
    possíveis”
     Filosofia Ruby
1995
Dave Thomas


   2001
http://www.ruby-lang.org
Thomas Enebo           2006




               JRuby


                 Ruby escrito
                100% em Java
WTF?!?
WTF?!?
http://rubyonrails.org/
Pilares
CoC
Convention over Configuration
DRY
Don’t Repeat Yourself
MVC
Browser
Browser



ApplicationController
Browser



ApplicationController


     Controller
Browser



ApplicationController


     Controller         Model
Browser



ApplicationController


     Controller         Model



                         DB
Browser



ApplicationController


     Controller         Model



                         DB
Browser



ApplicationController


     Controller         Model



                         DB
Browser



       ApplicationController


            Controller         Model



View                            DB
Aplicação
Configurações
Schema evolution




Testes
Controller




Model




View
Testes
Testes
 Test All The Fucking Time!
TDD
  Test Driven Development




BDD
Behavior Driven Development
RSpec


it "should require acceptance of terms of service" do
    @job.attributes = valid_job_attributes.except(:terms_accepted)
    @job.should_not be_valid
    @job.terms_accepted = false
    @job.should_not be_valid
    @job.terms_accepted = true
    @job.should be_valid
end
Cucumber

Feature: Job listing
 In order to see the job offers in my area and start working
 As a user
 I want to see a list of jobs filtered by type and location

 Scenario: Listing when there is no jobs
  Given there is no jobs
  When I go to "java"
  Then I should see "Desculpe, não existem vagas disponíveis."
  And the "OndeTrabalhar.com" field should contain "java"
Rails não escala!
Hoje o Redeparede.com
serve 7,5 milhões de
acessos por mês
usando Ruby on Rails.
Rails escala, depende
de você!
“Basecamp is now handling
 more than 50 million Rails
 requests per week. We're
 peaking out at around 200
     req/sec. Damn!”


   “Basecamp's average
  response time is 90ms
 and 87% of all requests
finish in less than 200ms.”
Não conheço ninguém que use Rails
Rails 3 =   +
Yehuda Katz
José Valim
Regis Pires




IFPI - Piauí
2
3
Formação Rails




RR-71: Desenvolvimento Ágil para     RR-75: Ruby e Rails avançados:
  Web 2.0 com Ruby on Rails        lidando com problemas do dia a dia
150



113                      113




 75
                  72



 38

                        2009
      0          2008
           10
          2007
E daí?
http://ondetrabalhar.com/ruby+ou+rails
http://slideshare.net/caueguerra

Rails - EXATEC2009