O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Ruby Rails Overview

6.218 visualizações

Publicada em

Ruby & Rails Overview, slides by Michal Poczwardowski, Ruby on Rails developer at @netguru

Publicada em: Software, Tecnologia
  • Download The Complete Lean Belly Breakthrough Program with Special Discount.  http://scamcb.com/bkfitness3/pdf
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • What are the best natural remedies for hair loss? ➤➤ https://bit.ly/2N8ZrEt
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • Protect your brain from memory loss with brain pill. find out more... ♣♣♣ https://bit.ly/2GEWG9T
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • How One Woman Discovered the Female Fat-Loss Code Missed by Modern Medicine And Lost 84 pounds Using a Simple 2-Step Ritual That Guarantees Shocking Daily Weight Loss >> ♣♣♣ http://scamcb.com/poundinc/pdf
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • Have You Seen Mike Walden's new holistic acne System yet? It's called Acne No More I've read the whole thing (all 223 pages) and there's some great information in there about how to naturally and permanently eliminate your acne without drugs, creams or any kind of gimmicks. I highly recommend it - it's very honest and straightforward without all the hype and b.s. you see all over the net these days. Here's the website where you can get more information ♣♣♣ http://scamcb.com/buk028959/pdf
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui

Ruby Rails Overview

  1. Ruby & Rails Overview brought by Michal Poczwardowski and Gdansk 11/05/15
  2. Michal Poczwardowski Ruby on Rails developer michal.poczwardowski@netguru.co
  3. Software house web&mobile
  4. Software house web&mobile
  5. Agenda Part 1 ruby Part 2 rails
  6. Part 1 ruby
  7. Ruby is a dynamic, scripting, object- oriented language...
  8. ‘Programming languages must feel natural to programmers.’ Yukihiro "Matz" Matsumoto
  9. hello = ‘Hello world!’ puts hello Hello world
  10. Try ruby in a browser! tryruby.org
  11. www.bloc.io/ruby-warrior Control brave knight using ruby
  12. Why ruby is so cool?
  13. #1: puts ‘Yes’ if ‘Work’.starts_with? ‘W’ #2: population = 12_000_000 #3: misterious_number.between?(10, 20) Like a natural language
  14. def really? true end Aesthetic
  15. 1: numbers = [] 2: for i in [1,2,3,4] 3: numbers << i ** 2 4: end 5: numbers # => [1,4,9,16] Elegant - NON ruby-way solution
  16. numbers = [1,2,3,4].map { |i| i ** 2 } numbers # => [1,4,9,16] Elegant - ruby-way solution
  17. Everything is an object!
  18. 42
  19. 42.times { puts ‘Awesome’ } Fixnum object
  20. :001 > 1.class => Fixnum :002 > (2.2).class => Float :003 > [].class => Array :004 > "Politechnika Gdańska".class => String :005 > nil.class => NilClass :006 > {}.class => Hash Output from irb
  21. Classes, objects 01: class School 02: attr_reader :name 03: 04: def initialize(name) 05: @name = name 06: end 07: 08: def hello 09: puts “Hello #{name}” 10: end 11: end school = School.new(‘PG’) school.hello # => ‘Hello PG’
  22. - high performance / lower level stuff - multi-threading - graphics / data analysis Avoid ruby in case of
  23. Ruby is great at... Metaprogramming
  24. Example with send 01: class Rubyist 02: def face(mood) 03: send(mood) 04: end 05: 06: private 07: 08: def happy 09: ‘:)’ 10: end 11: 12: def sad 13: ‘:(‘ 14: end 15: end dev = Rubyist.new dev.face(:happy) # => ‘:)’ dev.face(:sad) # => ‘:(’
  25. Handle missing methods 1: class Rubyist 2: def happy; ‘:)’ end 3: def sad; ‘:(‘ end 4: 5: def method_missing(name) 6: ‘:?’ 7: end 8: end dev = Rubyist.new dev.happy # => ‘:)’ dev.sad # => ‘:(’ dev.excited # => ‘:?’ dev.worried # => ‘:?’
  26. Define own methods 01: class Rubyist 02: FACES = { 03: happy: ‘:)’, 04: sad: ‘:(’, 05: excited: ‘;D’, 06: angry: ‘:[‘ 07: } 08: 09: FACES.each do |key, value| 10: define_method(key) { value } 11: end 12: end dev = Rubyist.new dev.happy # => ‘:)’ dev.sad # => ‘:(’ dev.angry # => ‘:[’ dev.excited # => ‘;D’
  27. Everything changes 1: class String 2: def with_smile 3: self + ‘ :)’ 4: end 5: end ‘Sad string’.with_smile # => ‘Sad string :)’
  28. ‘With great power comes great responsibility.’ Unkle Ben
  29. Write tests!
  30. Example rspec describe Rubyist do subject { described_class.new } describe ‘#happy’ do it ‘returns happy face’ expect(subject.happy).to eq ‘:)’ end end end
  31. library -> gem
  32. rubygems.org/stats - 9/05/15
  33. Gemfile 01: source 'https://rubygems.org' 02: 03: gem ‘rails’, ‘4.2.1’ 04: gem ‘nokogiri’ 05: gem 'stripe', git: 'https://github.com/stripe/stripe-ruby' 06: 07: group :test do 08: gem ‘rspec-rails’ 09: end
  34. Part 2 ruby on rails
  35. Rails is a web application development framework
  36. ‘Powerful web applications that formerly might have taken weeks or months to develop can be produced in a matter of days.’ Tim O’Reilly
  37. Websites powered by Rails
  38. isitrails.com
  39. Convention over Configuration
  40. Structure
  41. controllers models views routes.rb, database.yml Gemfile
  42. MVC
  43. controller model view browser DB routes web server
  44. Let’s prepare some code
  45. $ rails generate model Post title:string content:text invoke active_record create db/migrate/20150509232514_create_posts.rb create app/models/post.rb invoke rspec create spec/models/post_spec.rb invoke factory_girl create spec/factories/posts.rb Magic spells
  46. 01: class CreatePosts < ActiveRecord::Migration 02: def change 03: create_table :posts do |t| 04: t.string :title 05: t.text :content 06: 07: t.timestamps 08: end 09: end 10: end Migration
  47. MVC in action
  48. http://localhost:3000/
  49. 127.0.0.1 - GET /index.html HTTP/1.0" 200 2326
  50. get ‘/’, to: ‘welcome#index’
  51. class WelcomeController < ApplicationController def index @posts = Post.all end end
  52. class Post < ActiveRecord::Base end
  53. class Post < ActiveRecord::Base end
  54. class WelcomeController < ApplicationController def index @posts = Post.all end end
  55. <ul> <% @posts.each do |post| %> <li> <%= post.title %> </li> <% end %> </ul> ERB
  56. %ul - @posts do |post| %li =post.title HAML
  57. <html> … <body> … <%= yield %> … </body> </html>
  58. http://localhost:3000/
  59. This is almost the end...
  60. Don’t forget to visit netguru.co and our box no. 20
  61. Thanks!

×