L
L
Leonid K2016-12-30 14:10:46
Ruby on Rails
Leonid K, 2016-12-30 14:10:46

How to pass argument to anonymous function in hash?

There is ruby ​​code

a = {'hello' => proc { |hello| print hello}}
a['hello']('world')

On startup it says
/home/leonid/docs/prog/ruby/trys.rb:2: syntax error, unexpected '(', expecting end-of-input
a['chto-to']('world')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Demidenko, 2016-12-30
@mreluzeon

a = {'hello' => proc { |hello| print hello } }

a['hello'].call('world') # можно так
a['hello']['world'] # можно так
a['hello'].('world') # можно так

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question