I
I
iMa3str02015-02-20 16:50:11
ruby
iMa3str0, 2015-02-20 16:50:11

What does underscore(_) mean in pipes?

Let's say in this code? Why does ,_ come after key?
hh.select{|key,_| params[key] == ""}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Vsk, 2015-02-20
@viktorvsk

Placeholder for the last used variable:
stackoverflow.com/questions/9559561/where-and-how-...
The example is very strange, its meaning is not clear at all. But if you try to reproduce it:

hh = { test: 1}
params = { test: '' }
hh.select{|key,_| params[key] == ""} # { test: 1}
hh.select{|key| params[key] == ""} # { test: 1}

We will see that there is no difference. Perhaps there were some artifacts in the old (1.8, 1.9) versions of the interpreters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question