From: Wybo Dekker Date: 2005-08-10T22:08:12+09:00 Subject: Re: passing a method Robert Klemme wrote: > IMHO a superior solution would be to use a block instead of argument > option_handler. AFAICS you have only one such callback and that's exactly > what blocks are for. If you want access to the current instance you can > use instance_eval: > > def init(needed,defaults,&option_handler) > .... > # handle options > instance_eval &option_handler > .... > end but that would need, in the calling program, something like init(needed,defaults) { handle_options } which I feel is less straightforward/consequent than init(needed,defaults,:handle_options) > Also, for setting instance variables, this idiom is better (because it > avoids evil eval and you don't need special handling of nil): > > defaults.each {|k,v| instance_variable_set("@#{k}", v)} Nice! I did'nt know about instance_variable_set yet. Learned a lot today, thanks! -- Wybo