From: Nit Khair Date: 2008-10-22T20:54:19+09:00 Subject: Re: Is there a method_eval or similar thing ? Sandro Paganotti wrote: > I think that maybe you can wrap everything in a class: > > class Ask > def initialize(question) > @question = question; @h={} > yield(self) > end > def actionbind(key, &block) > @h[key] = block > end > end > > Ask.new("Do you wish to proceed?") do |question| > question.actionbind(:yes){ puts "user pressed yes" } > question.actionbind(:no) { puts "user pressed no" } > end Thanks, I will be using this whereever there are classes, but would like to know, is there any way i can do it with methods. I know i could define the hash as a global (or maybe module level object) but that would not be a clean solution. There is also one question I would like to ask as a ruby newbie (struggling to grow up). Is the above approach of passing blocks to an ask method making it more "rubyish" or better than returning the input character and letting the user decide what to do. -- Posted via http://www.ruby-forum.com/.