¿Cómo se llama el operador -> en Ruby?
-
¿Cómo se llama el operador
->
como en el siguiente?->(...) do ... end
-
¿No son equivalentes los siguientes fragmentos de código?
succ = ->(x) {x + 1} succ = lambda {|x| x + 1}
3 answers
En el Lenguaje de programación Ruby ("Methods, Procs, Lambdas, and Closures"), un lambda definido usando ->
se llama lambda literal.
succ = ->(x){ x+1 }
succ.call(2)
El código es equivalente al siguiente.
succ = lambda { |x| x + 1 }
succ.call(2)
De manera Informal, he oído que se llama stabby lambda o stabby literal.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-10 08:41:35
=>
== Hash Rocket
Separa las claves de los valores en un literal de mapa de hash.
->
== Dash Rocket
Se usa para definir un literal lambda en Ruby 1.9.X (sin args) y Ruby 2.X (con args). Los ejemplos que usted da (->(x) { x * 2 }
& lambda { |x| x * 2 }
) son de hecho equivalentes.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-28 14:35:09
Cohete Lambda
Lo obtuve de este artículo. Pero primero una búsqueda de Google para ruby lambda taquigrafía http://ruby-journal.com/becareful-with-space-in-lambda-hash-rocket-syntax-between-ruby-1-dot-9-and-2-dot-0/
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-11-12 22:30:31