N
Nathan
Hi,
This might be something really simple, but I'm trying to write a
console-based menu for my program. I've done this before in a
procedural language, but I decided to try and port what I've done to
ruby, because it'll make other parts of my program far easier. My
program has a few menus, so it'd be nice to have re-usable code (which
the procedural version didn't have much of).
The best way I've come up with is to pass the method calls which are
executed by each menu item as procs, but this requires passing them
around between two objects internally. (I haven't completely decided
how I'm going to structure the code which passes the procs... I have
an idea, but I'll cross that when I come to it)
Now, the Item class, which each menu item is an object of, doesn't
work as expected... take a look here: http://pastie.caboo.se/163781.
When I try to call myItem.execute!, it complains "no block given". If
I call myItem.execute! { 2 + 1}, then it works, but that's not what I
want...
I've also included the Menu class, just in case anybody has any advice
as to how to do the whole thing better.
Thanks,
-Nathan
This might be something really simple, but I'm trying to write a
console-based menu for my program. I've done this before in a
procedural language, but I decided to try and port what I've done to
ruby, because it'll make other parts of my program far easier. My
program has a few menus, so it'd be nice to have re-usable code (which
the procedural version didn't have much of).
The best way I've come up with is to pass the method calls which are
executed by each menu item as procs, but this requires passing them
around between two objects internally. (I haven't completely decided
how I'm going to structure the code which passes the procs... I have
an idea, but I'll cross that when I come to it)
Now, the Item class, which each menu item is an object of, doesn't
work as expected... take a look here: http://pastie.caboo.se/163781.
When I try to call myItem.execute!, it complains "no block given". If
I call myItem.execute! { 2 + 1}, then it works, but that's not what I
want...
I've also included the Menu class, just in case anybody has any advice
as to how to do the whole thing better.
Thanks,
-Nathan