<p>I'm trying to do Ruby password input with the <a href="http://highline.rubyforge.org/" rel="noreferrer">Highline gem</a> and since I have the user input the password twice, I'd like to eliminate the duplication on the blocks I'm passing in. For example, a simple version of what I'm doing right now is:</p>

<pre><code>new_pass = ask("Enter your new password: ") { |prompt| prompt.echo = false }
verify_pass = ask("Enter again to verify: ") { |prompt| prompt.echo = false }
</code></pre>

<p>And what I'd like to change it to is something like this:</p>

<pre><code>foo = Proc.new { |prompt| prompt.echo = false }
new_pass = ask("Enter your new password: ") foo
verify_pass = ask("Enter again to verify: ") foo
</code></pre>

<p>Which unfortunately doesn't work. What's the correct way to do this?</p>

I don't think the language supports a construct like this. The only way I can see to generalize this in any way is:
```
```
def foo(prompt)
  prompt.echo = false
end
new_pass = ask("Enter your new password: ") { |prompt| foo(prompt) }
verify_pass = ask("Enter again to verify: ") { |prompt| foo(prompt) }
```
```
It doesn't really shorten the code, though it does remove some duplication--if you wanted to do more than set
```
prompt.echo
```
to
```
false
```
, you'd only have to add code in one place.