--1926193751-1895070519-1209818709585
Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-1895070519-1209818709=:8585"

  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--1926193751-1895070519-1209818709585
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

Hi ...  <- private joke :-)

On Sat, 3 May 2008, Iñaki Baz Castillo wrote:

> 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?

Right; you can't say, for example,

   "a string" = 3

and every method call returns an object.

>> 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.

You could combine these techniques, actually, if you did something
like:

   class Message
     def from_header=(h)
       self.from_header.replace(h)
     end
   end

That's almost pseudo-code, but the point is you could then do:

   message.from_header = message.to_header

or whatever. That's the great thing about the "="-methods; they let
you use assignment semantics for method calls, and you can of course
define the method yourself.


David

-- 
Rails training from David A. Black and Ruby Power and Light:
   INTRO TO RAILS         June 9-12            Berlin
   ADVANCING WITH RAILS   June 16-19           Berlin
   INTRO TO RAILS         June 24-27           London (Skills Matter)
See http://www.rubypal.com for details and updates!
--1926193751-1895070519-1209818709585--
--1926193751-1895070519-1209818709585--