Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Do Ruby ao Ruby on Rails em 3hs

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

Do Ruby ao Ruby on Rails em 3hs

Curso de Ruby on Rails ministrado na Jornada Acadêmica da FACIN (PUC-RS)

Avatar for Jean Carlo Emer

Jean Carlo Emer

September 25, 2014
Tweet

More Decks by Jean Carlo Emer

Other Decks in Technology

Transcript

  1. O front-end é a marcação, aparência, acessibilidade, usabilidade e performance

    da sua aplicação em múltiplas plataformas Front-end
  2. 1. Qualquer valor é um objeto 2. Objetos comunicam-se através

    de mensagens 3. Objetos mantém estado 4. Objetos são instâncias de uma classe 5. Classes são repositórios de operações Alan Kay (Smalltalk) considera fundamental em OOP: http://c2.com/cgi/wiki?AlanKaysDefinitionOfObjectOriented
  3. OOP to me means only messaging, local retention and protection

    and hiding of state- process, and extreme late binding of all things. - Alan Kay
  4. $ _

  5. Numeric String Symbol Array Hash 1,  2,  3.1   'string'

      :symbol   [1,  'string']   {  key:  'value'  } Algumas Core Classes do Ruby
  6. 1  +  2
 =>  3   5  *  5  +

     2
 =>  27   'Ruby  '  +  '  on  '  +  '  Rails'
 =>  "Ruby    on    Rails"
  7. [1,  3]  +  [2]   [1,  2]  -­‐  [2]  

    'I  like  Ruby  /  '  *  4
  8. [1,  3]  +  [2]  
 =>  [1,  3,  2]  

    [1,  2]  -­‐  [2]
 =>  [1]   'I  like  Ruby  /  '  *  4
 =>  "I  like  Ruby  /  I  like  Ruby  /  I   like  Ruby  /  I  like  Ruby  /  "
  9. A documentação das classes da linguagem é uma ótima referência

    http://www.ruby-doc.org/core-2.1.2/Array.html http://www.ruby-doc.org/core-2.1.2/String.html
  10. class  Task
    def  initialize(name)
        @name  =

     name
    end
 
    def  name
        @name
    end
 end
  11. class  String
    def  hello
        "Hello,  #{self}"


       end
 end   "Jean".hello
 =>  "Hello,  Jean"
  12. class  Task    def  initialize(name)          @name

     =  name      end            def  to_s          @name      end   end   ! puts  Task.new  "Clean  the  house"
  13. class  Task      def  +(task)        

     @name  +=  "  and  #{task.name}"      end
 end   ! a  =  Task.new  "Clean  the  house"   b  =  Task.new  "Take  out  the  trash"   ! puts  a  +  b
  14. class  Person      attr_accessor  :name,  :age   !  

     def  initialize(name,  age)          @name,  @age  =  name,  age      end   !    def  >(person)          age  >  person.age      end   end
  15. class  EventTask  <  Task      attr_reader  :hours   !

       def  initialize(name,  hours)          @name    =  name          @hours  =  hours      end   !    def  to_s          "#{hours.to_s}  ~  #{name}"      end   end
  16. class  EventTask  <  Task      attr_reader  :time   !

       def  initialize(name,  time)          @name,  @time  =  name,  time      end   !    def  to_s          "#{time.to_s}  ~  #{name}"      end   end
  17. module  Status      def  done?        

     @done  ||  false      end   !    def  done!          @done  =  true      end   end
  18. module  Status      def  done?        

     @done  ||  false      end   !    def  done!          @done  =  true      end   end
  19. class  Issue      include  Status      attr_reader  :name

      !    def  initialize(name)          @name  =  name      end   end   ! class  Task      include  Status   end
  20. issue  =  Issue.new('The  refrigerator  is  broken')   task    =

     Task.new('Fix  the  refrigerator')   ! issue.done!   puts  issue.done?   ! task.done!   puts  task.done?
  21. class  Sample      def  method_missing(m,  *args,  &block)    

         "Method  '#{m}'  missing!"      end   end   ! puts  Sample.new.some_method
  22. HTMLForm.generate(STDOUT)  do      comment  "This  is  a  simple  HTML

     form"      form  name:  "registration",  action:  "/"  do          content  "Name:"          input  name:  "name"          content  "Address:"          textarea  name:  "address",  rows:  6,  cols:  40  do              "Please  enter  your  mailing  address  here"          end   !        button  do              "Submit"          end      end   end
  23. =>  <!-­‐-­‐  This  is  a  simple  HTML  form  -­‐-­‐>  

    ! <form  name='registration'  action='http:// www.example.com/register.cgi'  method='GET'   enctype='application/x-­‐www-­‐form-­‐urlencoded'>      Name:      <input  name='name'  type='text'/>            Address:      <textarea  name='address'  rows='6'  cols='40'          Please  enter  your  mailing  address  here      </textarea>   !    <button  type='submit'>Submit</button>   </form>
  24. A facilidade em criar DSLs em Ruby é um dos

    maiores poderes da linguagem
  25. $ _

  26. Bundle constrói o mapa de dependências e mantém as gems

    adequadas para o funcionamento da aplicação