# Method ref in menu

**URL:** <https://www.ruby-forum.com/t/method-ref-in-menu/259265>\
**Category:** Ruby-Forum\
**Created:** [April 17, 2020, 12:49am UTC](https://www.ruby-forum.com/t/method-ref-in-menu/259265 "2020-04-17T00:49:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubynewbee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/74df32/32.png) [@rubynewbee](https://www.ruby-forum.com/u/rubynewbee)\
**Post date:** [April 17, 2020, 12:49am UTC](https://www.ruby-forum.com/t/method-ref-in-menu/259265/1 "2020-04-17T00:49:57Z")

</div>

Ruby 1.91 on Debian 7.3 running on Pentium 3  
trying to write menu like so:  
def foo; end  
def bar; end  
mHash={‘f’=\>[‘foo’,foo], ‘b’=\>{‘bar’,bar]}  
def menu(mH)  
mH.each\_key { |k| puts k + ’ ’ + mH[k][0] }

```
puts 'choice? '
ch=gets.chomp
 if mH.has_key?( ch )
    mH[ch][1]
end

```

end

Not really knowing what I’m doing yet I’ve tried various sigils both in the hash definition and the execution call with no joy. Is 1.9.1 too old to have this functionality or have I just not found it yet?  
I did find a posting by Jim Weirich of reference.rb but it didn’t fly here.  
I’m really just looking for info since I’ve already rewritten menu using a case/when/then but it’s really clunky.  
Thanks.  
PS: ‘Stay at home’ is a good time to explore another language isn’t it?

---

<div class="post-metadata">

**Author:** ![pcl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecae2f/32.png) [@pcl](https://www.ruby-forum.com/u/pcl)\
**Post date:** [April 17, 2020, 2:05am UTC](https://www.ruby-forum.com/t/method-ref-in-menu/259265/2 "2020-04-17T02:05:01Z")

</div>

Object#method is probably what you want: [class Object - RDoc Documentation](https://docs.ruby-lang.org/en/2.7.0/Object.html#method-i-method) (it appears to have been in 1.9.1, according to my PickAxe book!).

```auto
> def foo; puts "in foo"; end
 => :foo 
> hash = {'f' => method(:foo)}
> hash['f'].call
in foo
 => nil 

```

P.S. have fun with Ruby!

---

<div class="post-metadata">

**Author:** ![rubynewbee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/74df32/32.png) [@rubynewbee](https://www.ruby-forum.com/u/rubynewbee)\
**Post date:** [April 17, 2020, 2:33pm UTC](https://www.ruby-forum.com/t/method-ref-in-menu/259265/3 "2020-04-17T14:33:04Z")

</div>

Worked perfectly, many thanks.  
Blessings on your house.
