--00c09f8e5bcd84b3960473b3a9cf
Content-Type: text/plain; charset=ISO-8859-1

Morning Matt,

...
>
>
>
> I do have a quick question, I thought the way method_missing worked, was
> you could call that method using any method name, so I tried it for heck
> of it just because I never used it, i did blah(:parameter_name), and it
> complained that there was no blah method, which I thought would cause
> the method_missing method to run.  I changed the method to be
> get_val(name, *args) and it worked.
>

Probably poor wording on my part in terms of the parameters names for
method_missing. This might look a little better

def method_missing(method_name, *args)
    #this will allow a call to Signal.xxx to return xxx automatically

    #no need to define every variable
    return @variables[method_name].value if @variables.key?(method_name)
    super
  end

What method_missing does is give you the name of the method as the first
parameter and then the *args is just an array I believe that holds any
number of variables passed in. It allows method_missing to handle things
like

blah(a, b, c, d, e) as easily as blah(a) as blah()

In each of those cases method_missing would be called with "blah" for the
method_name and *args would contain whatever was in the ().

So in this case if you wanted the freq parameter you could call something
like

x  ignal.new
x.add_variable('freq', 10)
x.freq #returns 10

Method missing will still fire an unknown method error if you use a
parameter name that doesn't exist - that's what the call to super does in
the method_missing function. It checks it's list of parameters for what you
want and then just treats it as a normal bad method call.

Always remember that pp is a great help to see things as they exist in the
code. If you wanted to check out what method_missing was getting an option
would be to add require 'pp' to the top of your code and then modify
method_missing to look something like this.

def method_missing(method_name, *args)
  #this will allow a call to Signal.xxx to return xxx automatically

  pp 'Method missing got the following', method_name, *args
  #no need to define every variable
  return @variables[method_name].value if @variables.key?(method_name)
  super
end


Hope that clears it up a little.

John

--00c09f8e5bcd84b3960473b3a9cf--