$30 off During Our Annual Pro Sale. View Details »

Advanced Ruby for Rails Devs, by Sherif Abushadi

Paul Burt
October 23, 2015

Advanced Ruby for Rails Devs, by Sherif Abushadi

From the October 23rd (2015) SFRails meetup:
http://www.meetup.com/SFRails/events/225588522/

Paul Burt

October 23, 2015
Tweet

More Decks by Paul Burt

Other Decks in Programming

Transcript

  1. Advanced Ruby
    for Rails developers

    View Slide

  2. What are we talking about?
    Ruby claims to make things easier for developers, but
    sometimes that flexibility feels like complexity.
    For example, Ruby supports 4 different ways to reference
    (and later execute) a piece of code:
    - methods
    - blocks
    - procs
    - lambdas

    View Slide

  3. We’re talking about: methods and blocks

    View Slide

  4. We’re talking about: dynamic methods

    View Slide

  5. We’re talking about: procs and lambdas
    what if ...
    you could treat code as if it were data or an object?
    that’s what procs and lambdas do for you. they let you wrap
    code and pass it around in variables and collections.
    and the two are essentially the same thing except for a
    little syntax and 2 differences in behavior.

    View Slide

  6. We’re talking about: procs and lambdas
    both of them are closures (they keep a reference to the
    current context) and respond to the call() method

    View Slide

  7. We’re talking about: lambdas
    Lambdas:
    - enforce arity
    - return to the scope in which they were called

    View Slide

  8. We’re talking about: procs
    Procs:
    - don’t enforce arity
    - return to the scope in which they were defined

    View Slide

  9. Time Check…
    let’s code?

    View Slide

  10. We’re talking about: open source for study
    Sample Project: GitLab
    - github.com/gitlabhq/gitlabhq
    - Self hosted Git management software
    Fast and easy Git repositories, hosted either on your own
    or at Gitlab.com. Create projects and repositories, manage
    access and perform collaborative code reviews.
    - 200,000 lines of code and 600 classes among 2800 files

    View Slide

  11. We’re talking about: Rails
    link
    sample project: GitLab

    View Slide

  12. We’re talking about: Rails
    guides.rubyonrails.org/active_record_querying.html

    View Slide

  13. We’re talking about: Rails
    body.call()

    View Slide

  14. We’re talking about: Rails sample project: GitLab
    link

    View Slide

  15. We’re talking about: Rails
    api.rubyonrails.org
    /classes/AbstractController/Callbacks/ClassMethods.html

    View Slide

  16. We’re talking about: Rails

    View Slide

  17. summary
    - Ruby let’s you “name” a piece of code to run later.
    - methods and blocks can’t be passed around like objects
    - procs and lambdas can.
    what else?
    - embrace the confusion
    - have faith in your own work
    - keep exploring, playfully

    View Slide

  18. - Questions?
    - check out opensourcerails.com
    - thanks!
    Sherif Abushadi
    [email protected]

    View Slide