Sipper Dynamic Methods & Ruby Symbol Table

8 views
Skip to first unread message

phoenix6789

unread,
Jan 19, 2010, 10:24:15 AM1/19/10
to Sipper
Hi,

This is perhaps more of a basic Ruby programming question, but while
debugging the SipURI issue last night I stumbled upon this piece of
code that totally confused me:

In Message::parse_headers(), around line 300, there is this block:

if @headers[hn.to_sym]
self.send(("add_"+hn.to_s).to_sym, h[1])
else
self.send((hn.to_s+"=").to_sym, h[1])
end

I eventually found the problem, but I still don't understand how this
piece of code ends up calling the piece of code I ended up in. In my
path execution I was debugging the parsing and population of the
contact header. The header name turned out to be "contact", and h[1]
contained the header value to parse. Where I got stuck was this line:

self.send((hn.to_s+"=").to_sym, h[1])

I'm ok with the self.send, but can you tell me how "contact=".to_sym()
results in the SipURI::assign(str) method being called.

Clearly I need to study more about dynamic methods and the ruby symbol
table, but if you could provide me a very short explaination for how
the association is made I'll continue to stare at it until it makes
sense.

thanks,

Dave Adams

Reply all
Reply to author
Forward
0 new messages