1

What is exactly the meaning of this Ruby on Rails Syntax

options = ->(p) {{controller: 'clients', subdomain: "m.#{Rails.env}"}.merge!(p)}

I have never encountered this syntax before: ->(p).

I could not even find resources on that on google. Does anyone have a tutorial about that?

anyavacy
  • 1,618
  • 5
  • 21
  • 43
  • If you'd like to delve more deeply into Ruby lambdas, I have a conference presentation about them posted on YouTube at https://www.youtube.com/watch?v=hyRgf6Qc5pw; slide show is at https://speakerdeck.com/keithrbennett/ruby-lambdas-functional-conf-bangalore-oct-2014. – Keith Bennett Apr 25 '16 at 17:05
  • This SO thread could be interesting for you: http://stackoverflow.com/a/28215281/3033649 – markets Apr 25 '16 at 17:06
  • You have a smorgasbord of choices for calling `options`: `options.call(p)`, `options[p]`, `options.yield(p)`, `options===p` and the still-supported-but-on-its-way-out `options.(p)`. – Cary Swoveland Apr 25 '16 at 17:36

1 Answers1

5

It is just additional lambda syntax (since Ruby version 1.9). Old syntax:

options = lambda { |p| { controller: 'clients', subdomain: "m.#{Rails.env}"}.merge!(p)}
Ilya
  • 13,337
  • 5
  • 37
  • 53