Posted over 6 years ago. Visible to the public. Repeats.
Defining and calling lambdas or procs (Ruby)
There are different ways to define a lambda or proc in ruby:
-
with
lambda
-keywordCopytest = lambda do |arg| puts arg end
-
with the lambda literal
->
(since ruby 1.9.1)Copytest = -> (arg) do puts arg end
-
with the
proc
keyword (which defines a lambda that does not test the given number of arguments):Copytest = lambda do |arg| puts arg end
And there are different ways to call them:
-
call
(we prefer this)Copytest.call('hello world')
-
Square brackets (could easily be mistaken for a hash)
Copytest['hello world']
-
.()
(weird, isn't it?)Copytest.('hello world')
Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for unsupported versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2).