I
Iñaki Baz Castillo
Hi, I've an Array containing complex objects of Header class:
=2D------------------------------------
class Header
#attributes:
# - @name
# - @original_value
# - @parsed_value
# ...
end
class Message
#attributes:
# - @first_line
# - @headers =3D
# [header_1, header_2, header_3...]
# - @body
end
=2D------------------------------------
Just some headers are parsed, and for a header "From", @name attribute can =
be:
"From", "from", "FROM", "F", "f" ... =3D> /^(from|f)$/i
Now I need to access a specifi header ("From" for example) several times an=
d I=20
want to avoid doing a "Header.find { |h| h.name =3D~ /^(from|f)$/i }" for =
each=20
access,so:
class Message
def header(name)
Header.find { |h| h.name =3D~ /^(from|f)$/i }
end
end
But doing message.header("From") for each access will be not very efficient=
=20
and I try to avoid it. Is there any other way?
I could doing an assigment just the first time:
message.hdr_from =3D message.header("From")
...do_somethig_with_hdr_from... :
message.hdr_from.parsed_value.uri
message.hdr_from.parsed_value.uri.name
message.hdr_from.parsed_value.display_name
...
So "hdr_from" is like a pointer to header("From"), but it's not valid for m=
e=20
since I need the possibility of doing a re-assignement:
header("From") =3D header("To")
So if after doing that I use "message.hdr_from" I will access to the previo=
us=20
value of "From" header instead of the new one.
In fact, what I'm looking for is a persister pointer, concept that I alread=
y=20
know doesn't exist in Ruby
Thanks for any suggestion.
=2D-=20
I=C3=B1aki Baz Castillo
=2D------------------------------------
class Header
#attributes:
# - @name
# - @original_value
# - @parsed_value
# ...
end
class Message
#attributes:
# - @first_line
# - @headers =3D
# [header_1, header_2, header_3...]
# - @body
end
=2D------------------------------------
Just some headers are parsed, and for a header "From", @name attribute can =
be:
"From", "from", "FROM", "F", "f" ... =3D> /^(from|f)$/i
Now I need to access a specifi header ("From" for example) several times an=
d I=20
want to avoid doing a "Header.find { |h| h.name =3D~ /^(from|f)$/i }" for =
each=20
access,so:
class Message
def header(name)
Header.find { |h| h.name =3D~ /^(from|f)$/i }
end
end
But doing message.header("From") for each access will be not very efficient=
=20
and I try to avoid it. Is there any other way?
I could doing an assigment just the first time:
message.hdr_from =3D message.header("From")
...do_somethig_with_hdr_from... :
message.hdr_from.parsed_value.uri
message.hdr_from.parsed_value.uri.name
message.hdr_from.parsed_value.display_name
...
So "hdr_from" is like a pointer to header("From"), but it's not valid for m=
e=20
since I need the possibility of doing a re-assignement:
header("From") =3D header("To")
So if after doing that I use "message.hdr_from" I will access to the previo=
us=20
value of "From" header instead of the new one.
In fact, what I'm looking for is a persister pointer, concept that I alread=
y=20
know doesn't exist in Ruby
Thanks for any suggestion.
=2D-=20
I=C3=B1aki Baz Castillo