A PR Has Been Submitted

A PR Has Been Submitted

Have you ever submitted a PR and it just comes back to you in 5 minutes? Maybe you should have reviewed your own PR first. Here's some tips on making your PR better

7ae2c5cad3f71b75706b118c3d06c7b2?s=128

Paulo Ancheta

October 10, 2017
Tweet

Transcript

  1. @PauloAncheta

  2. None
  3. None
  4. None
  5. None
  6. None
  7. None
  8. A Pull Request Has Been Submitted

  9. None
  10. 1. Remove @instance_variables

  11. # test.rb puts @car puts car $ ruby test.rb NameError:

    undefined local variable or method `car` for main:Object
  12. # test.rb puts “#{@car} #{car}” $ ruby test.rb NameError: undefined

    local variable or method `car` for main:Object
  13. # test.rb puts @car.class puts “This car is #{@car}” $

    ruby test.rb NilClass This car is
  14. None
  15. # test.rb puts “This car is #{@car.capitalize}” $ ruby test.rb

    NoMethodError: undefined method `capitalize’ for nil:NilClass
  16. 2. Avoid Hash[key]

  17. Hash[ ]

  18. None
  19. None
  20. # test.rb hash = {a: {b: {c: {d: “ ”}}}}

    puts hash[:a][:b][:c][:d] $ ruby test.rb
  21. # test.rb hash = {a: {b: {c: {z: “ ”}}}}

    puts hash[:a][:b][:c][:d] $ ruby test.rb # nil
  22. # test.rb hash = {a: {b: {z: {d: “ ”}}}}

    puts hash[:a][:b][:c][:d] $ ruby test.rb NoMethodError: undefined method `[]' for nil:NilClass
  23. # test.rb hash = {a: {b: {c: {d: “ ”}}}}

    puts hash.dig(:a, :b, :c, :d) $ ruby test.rb
  24. # test.rb hash = {a: {y: {c: {d: “ ”}}}}

    puts hash.dig(:a, :b, :c, :d) $ ruby test.rb # empty output
  25. hash = {a: {y: {c: {d: “ ”}}}} puts hash.fetch(:a)

    .fetch(:b) .fetch(:c) .fetch(:d) $ ruby test.rb KeyError: key not found: :b # test.rb
  26. None
  27. 3. (rails) Use ! more

  28. 3. (rails) Use ! more

  29. None
  30. $ bin/rails c irb(main):1:0> Account.first.update(name: “this is too long”) Account

    Load (0.4ms) SELECT `accounts`.* FROM `accounts` ORDER BY `accounts`.`id` ASC LIMIT 1 (0.1ms) BEGIN Account Exists (0.2ms) SELECT 1 AS one FROM `accounts` WHERE (`accounts`.`token` = BINARY 'a6db14e97e1f9fe7' AND `accounts`.`id` != 1) LIMIT 1 (0.1ms) ROLLBACK false
  31. $ bin/rails c irb(main):1:0> Account.first.update!(name: “this is too long”) Account

    Load (0.4ms) SELECT `accounts`.* FROM `accounts` ORDER BY `accounts`.`id` ASC LIMIT 1 (0.1ms) BEGIN Account Exists (0.2ms) SELECT 1 AS one FROM `accounts` WHERE (`accounts`.`token` = BINARY 'a6db14e97e1f9fe7' AND `accounts`.`id` != 1) LIMIT 1 (0.1ms) ROLLBACK ActiveRecord::RecordInvalid: Validation failed: Name is too long (maximum is 20 characters) … … …
  32. None
  33. Conclusion

  34. None