Functional Programming in Ruby

Proc, Lambda, and Beyond

Agnieszka Maล‚aszkiewicz at Fractal Soft

I joined Ruby community when...

Ruby 1.9.3
Rails 3.0

Horse holding a cat slide from Wat presentation

A lightning talk by
Gary Bernhardt from CodeMash 2012

Agenda

  • ๐Ÿข Block
  • ๐Ÿ” Procs
  • ๐Ÿ’ƒ Lambdas
  • ๐Ÿšช Closures
  • ๐Ÿง™โ€โ™‚๏ธ Crazy stuff
  • ๐Ÿ“‘ Summary

๐Ÿ“ˆ Function

๐Ÿข Block

๐Ÿ” Proc

๐Ÿค” How call Proc object?

๐Ÿ’ผ Proc in case

โ˜Ž๏ธ Call method with argument as proc

๐Ÿ’ƒ Lambdas

๐Ÿšช Closures

๐Ÿง™โ€โ™‚๏ธ Crazy stuff

๐Ÿ—บ๏ธ map(&:name)

๐Ÿฆ„ Call map with argument method

#๏ธโƒฃ Hash in map

๐Ÿฆ“ Passing argument to map

1 + 2

๐Ÿคฏ

Summary

Types

  • ๐Ÿข block + yield
  • ๐Ÿ block + &b
  • ๐Ÿ” Proc.new
  • ๐Ÿ‘จโ€๐Ÿ’ป proc
  • ๐Ÿ’ƒ lambda
  • ๐Ÿค– method
Woman on Rails logo

womanonrails.com/presentations

### Links - [Wat lightning talk](https://destroyallsoftware.com/talks/wat) - [parsel.y](https://github.com/ruby/ruby/blob/master/parse.y#L4992-L5000) - [Why do two strings separated by space concatenate in Ruby?](https://stackoverflow.com/questions/23811203/why-do-two-strings-separated-by-space-concatenate-in-ruby/) - [Closure in Ruby](http://innig.net/software/ruby/closures-in-ruby) - [An Introduction to Proc, Lambdas and Closures in Ruby](https://www.youtube.com/watch?v=VBC-G6hahWA) - [Design Patterns in Ruby - Russ Olsen](http://www.amazon.com/Design-Patterns-Ruby-Russ-Olsen/dp/0321490452) - [Ruby doc](http://ruby-doc.org/) - [Functional Programming with Ruby](http://www.slideshare.net/tokland/functional-programming-with-ruby-9975242) - [Features of Functional Languages](http://www.sitepoint.com/functional-programming-techniques-with-ruby-part-i/) - [Ruby Proc doc 2.6](https://ruby-doc.org/core-2.6/Proc.html#method-c-new)
### Links - [Rubinius](https://github.com/rubinius/rubinius) - [Ruby current Proc doc](https://ruby-doc.org/current/Proc.html) - [Ruby Proc doc 1.9.1](https://ruby-doc.org/core-1.9.1/Proc.html) - [Ruby Proc doc 1.8.6](https://ruby-doc.org/core-1.8.6/Proc.html) - [Method#curry](https://www.rubydoc.info/stdlib/core/Method:curry) - [Ruby map(&:method) syntax - meaning & usage](https://womanonrails.com/one-line-map-ruby) - [Method object](https://ruby-doc.org/current/Method.html) - [Functional programming in Ruby](https://womanonrails.com/functional-programming-ruby) - [Iterators in Ruby](https://womanonrails.com/ruby-iterators) - [Things you didn't know about Ruby](https://womanonrails.com/things-you-dont-know-about-ruby)
Woman on Rails logotype

Agnieszka Maล‚aszkiewicz

agnieszka (at) fractalsoft (dot) org