From: "Iñaki Baz Castillo" Date: 2008-05-03T18:41:09+09:00 Subject: Re: How to access to an Array element without doing "find" each time El Sábado, 3 de Mayo de 2008, David A. Black escribió: > > So "hdr_from" is like a pointer to header("From"), but it's not valid for > > me since I need the possibility of doing a re-assignement: > > > >  header("From") = header("To") > > That's not legal Ruby. A method call isn't an lvalue. Oh, yes, you are right! Please, let me know if I understand correctly why: header("From") returns a value so I'm trying to do: value1 = value2 that is not legal, is it? > My advice is to try to learn to think in Ruby, so that you don't keep > experiencing frustration because of what you perceive Ruby as not > having. Believe me, Ruby is definitely feature-rich enough to parse > headers :-) Well, in fact I've already done the parser (using TreeTop magic). But it's not enought with parsing headers (as it would be in HTTP protocol) since I'm doing a SIP stack and it can be a proxy (so some headers are modified, new added, some deleted... and the rest of message remains equal and is forwarded to other server. That's why I need an efficient way of accessing the @header array of Header objets, parse just one of them and keep the whole message as it arrived. > A lot of Ruby objects need to change their state or contents, without > changing what object they are. Methods like Array#replace, > String#replace, and many others, do exactly that. Maybe your message > objects could "replace" headers with each other, or something like > that. Ok, so you mean that I should avoid using "=" and use objects methods to replace their content. Nice to know. Thanks a lot. -- Iñaki Baz Castillo