A
A
Alexander Wolf2014-11-23 12:46:38
ruby
Alexander Wolf, 2014-11-23 12:46:38

What does the construction -> {} mean?

Hey! I often see the design (arg) -> {}
I Know Coffee and there it denotes a function. However, a = (arg) -> { 920 }it doesn’t work :(
I googled it, but I didn’t find an answer. So, what does this construction mean?
The most interesting thing is that you have to use it yourself, without even understanding its meaning.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Vsk, 2014-11-23
@mannaro

It's a lambda (or proc )
In short, at its core, it's a callable object. Where you store an arbitrary block with arbitrary formal variables. And at any time you have the opportunity to call a method on itcall

a = -> { |time| User.where(created_at: time) }
...
a.call(Time.now)

When the brackets are before the lambda, it's just that the syntax is different

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question