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

30 slides en 30 minutes

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

30 slides en 30 minutes

Présentation sur Ruby @ ConFoo2016

Avatar for christianblais

christianblais

February 24, 2016

More Decks by christianblais

Other Decks in Programming

Transcript

  1. commit 6f7dea9 + patate = Patate.new(1) commit 850aecb + patate

    = Patate.new(2) - patate = Patate.new(1) commit a73bf19 + banane = Banane.new(3) $ git log > 6f7dea9 > 850aecb > a73bf19
  2. commit 6f7dea9 + patate = Patate.new(1) commit 850aecb + patate

    = Patate.new(2) - patate = Patate.new(1) commit a73bf19 + banane = Banane.new(3) $ git log -G”patate” > 6f7dea9 > 850aecb
  3. commit 6f7dea9 + patate = Patate.new(1) commit 850aecb + patate

    = Patate.new(2) - patate = Patate.new(1) commit a73bf19 + banane = Banane.new(3) $ git log -S”patate” > 6f7dea9
  4. $ x = Array.new(100) $ x.first; x.last $ x.second $

    x.third $ x.fourth $ x.fifth $ x.forty_two
  5. $ p = Post.create do |post| $ post.title = “x”

    * 200 $ end > <Post id=“1”> $ p.title.size > 100
  6. $ p = Post.create(title: nil) > MySQL::Error $ p =

    Post.create(title: “x”) > <Post id=“1”>
  7. python -mjson.tool $ !! | python -mjson.tool > { "hello1":

    "it is me", "hello2": "from the other side", "hello3": "from the outside" }
  8. ‣ 23 unicorns ‣ 9 ahoy ‣ 9 suck ‣

    6 wtf ‣ 3 ninja ‣ 2 python ‣ 1 shit
  9. class Pirate < ActiveRecord::Base belongs_to :parrot, :validate => true has_many

    :treasures, :as => :looter has_many :treasure_estimates has_one :ship has_many :birds, -> { order('birds.id ASC') } … end
  10. ## # Call this at the top of your tests

    when you absolutely # positively need to have ordered tests. In doing so, you're # admitting that you suck and your tests are weak. def self.i_suck_and_my_tests_are_order_dependent! class << self undef_method :test_order if method_defined? :test_order define_method :test_order do :alpha end end end
  11. $ rails server > Bundler can’t satisfy… $ bundle exec

    rails server > Run `bundle install` to… $ bundle install > Your bundle is complete! $ bundle exec rails server > Listening on 0.0.0.0:3000
  12. alias be = bundle check || bundle install && bundle

    exec $ be rails server > Dependencies are satisfied > Listening on 0.0.0.0:3000
  13. case x when ->(n) { n.even? } then :even when

    ->(n) { n.odd? } then :odd else :wtf end
  14. def code?(code) ->(resp) { resp.code == code } end case

    response when code?(200) then “Yeah!” when code?(400) then “Uhoh!” when code?(500) then “Shit!” else “I’m a teapot” end
  15. store(key, value) Associates the value given by value with the

    key given by key. key should not have its value changed while it is in use as a key (a String passed as a key will be duplicated and frozen).
  16. class A def foo(a, *b, &block) end end $ method

    = A.instance_method(:foo) > #<UnboundMethod: A#foo>
  17. break $ [1,2,3].map { |x| break } > nil $

    [1,2,3].map { |x| break(x) } > 1
  18. next $ [1,2,3].map { |x| next } > [nil, nil,

    nil] $ [1,2,3].map { |x| next(x) } > [1, 2, 3]
  19. def add(a, b) a + b end def subtract(a, b)

    a - b end def multiply(a, b) a * b end def divide(a, b) a / b end
  20. math = lambda do |fn, a, b| a.send(fn, b) end

    add = math.curry.(:+) subtract = math.curry.(:-) multiply = math.curry.(:*) divide = math.curry.(:/)
  21. $ add.(1, 2) > 3 $ subtract.(1, 2) > -1

    $ multiply.(1, 2) > 2 $ divide.(1, 2) > 0
  22. %q[ ] String non interpolée %Q[ ] String interpolée %r[

    ] Expression régulière interpolée %i[ ] Tableau non interpolé de symboles %I[ ] Tableau interpolé de symboles %w[ ] Tableau non interpolé de mots %W[ ] Tableau interpolé de mots %x[ ] Commande shell %s[ ] Symbole non interpolé
  23. $ %w[hello it’s me] > ["hello", "it’s", “me”] $ %i[hello

    it’s me] > [:hello, :it’s, :me] $ %r[hello it’s me] > /hello it’s me/
  24. ruby -run -e httpd . $ ruby -run -e httpd

    . -p 8000 > INFO WEBrick 1.3.1 > INFO ruby 2.2.3 (2015-08-18) > INFO pid=1766 port=8000