On Sat, 18 Jan 2003, Tom Sawyer wrote:

> but this does not free one from using respond_to? i.e. instead of: if
> respond_to?(:x), one would simply say: if x != nack.

i see your point, but see my post to david.  in general i love syntax
shortcuts, but i'm not comfortable about that because it hide exception
throwing...

> yes, close but ameth can't be local (right?) since it needs to respond. but
> you got the idea.

i guessed you might have looked up ameth in a table within the method :

  ameth = symtable [ :ameth ]

but no, it needn't be local.

> the reason: the code belongs to a mixin module. ameth is an optional method
> that the mixin can use, or not. whatever ameth returns it ultimately needs
> to be a stiring, but it is not unreasonable that it would return a symbol,
> thus the to_s. for validation purposes of course i have to make sure ameth
> does not return nil, and if it resolves to an empty string after the to_s
> then it's of no use either. does that explain it?

yes.

why not simply :

  def send (sym, *args)
    begin; super.send sym, *args; rescue NameError; end
  end

i guess you would then need to no what happened in try, thus the need for
something like the discussed NACK.  i suppose i can see your point now.

what about something similar to

  require 'singleton'
  module Nack
    class NotAcknowledged
      include Singleton
    end
    NACK = NotAcknowledged.instance
  end
  class Object # or better your class
    include Nack
    def method_missing (sym, *args)
      return NACK
    end
  end

  o = Object.new
  p o.meth 	  # #<Nack::NotAcknowledged:0x401836bc>#

i actually like that one (someone suggested it earlier).  it's short and
ignores exceptions, but it would be patently clear to anyone reading the code
that missing methods do not throw exceptions.

then you'd end up writing

if x != NACK...

lol.  guess that's what i you wanted all along.  just didn't see the whole
picture untill now!  ;-)

-a





-- 

 ====================================
 | Ara Howard
 | NOAA Forecast Systems Laboratory
 | Information and Technology Services
 | Data Systems Group
 | R/FST 325 Broadway
 | Boulder, CO 80305-3328
 | Email: ahoward / fsl.noaa.gov
 | Phone:  303-497-7238
 | Fax:    303-497-7259
 ====================================