Slide 1

Slide 1 text

Advanced Ruby for Rails developers

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

We’re talking about: methods and blocks

Slide 4

Slide 4 text

We’re talking about: dynamic methods

Slide 5

Slide 5 text

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.

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Time Check… let’s code?

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

We’re talking about: Rails

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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