I’m trying to create a Proc to pass to a method to find a key in a hash.
I’m checking to see if the key, “Open” exists:
<code>title = "Open"
block = Proc.new { |key, val| key == "'#{title}'" }
def my_method(block)
my_hash.any? &block => Always False!!!!
</code>
<code>title = "Open"
block = Proc.new { |key, val| key == "'#{title}'" }
def my_method(block)
my_hash.any? &block => Always False!!!!
</code>
title = "Open"
block = Proc.new { |key, val| key == "'#{title}'" }
def my_method(block)
my_hash.any? &block => Always False!!!!
The problem is that the title variable isn’t visible in my_method() so it fails.
I want the block to be created like this:
<code>block = Proc.new { |key, val| key == 'Open' }
</code>
<code>block = Proc.new { |key, val| key == 'Open' }
</code>
block = Proc.new { |key, val| key == 'Open' }
Then it will work. How do I force Ruby to convert the variable title to the constant, “Open”????
3