Can't marshal MatchData?

Folks,

I understand there are 4 kinds of things you can’t marshal: singleton
methods, IO objects, bindings, and … and … someone will fill in.

Why then, can’t you marshal MatchData objects? To wit:

irb(main):108:0> Marshal.dump(ms[63]).size
TypeError: can’t dump MatchData
from (irb):108:in `dump’
from (irb):108
from ?:0

[ms is an array of MatchData objects]

I don’t think MatchData is the fourth item in the incomplete list above.

Gavin

Folks,

I understand there are 4 kinds of things you can’t marshal: singleton
methods, IO objects, bindings, and … and … someone will fill in.

procs ?

I don’t think MatchData is the fourth item in the incomplete list above.

Maybe it’s the fifth :slight_smile:

Regards,

Brian.

···

On Wed, Aug 06, 2003 at 05:34:47PM +0900, Gavin Sinclair wrote:

“Gavin Sinclair” gsinclair@soyabean.com.au schrieb im Newsbeitrag
news:48928.203.185.214.34.1060113020.squirrel@webmail.imagineis.com

Folks,

I understand there are 4 kinds of things you can’t marshal: singleton
methods, IO objects, bindings, and … and … someone will fill in.

Why then, can’t you marshal MatchData objects? To wit:

irb(main):108:0> Marshal.dump(ms[63]).size
TypeError: can’t dump MatchData
from (irb):108:in `dump’
from (irb):108
from ?:0

[ms is an array of MatchData objects]

I don’t think MatchData is the fourth item in the incomplete list above.

Maybe a Regexp reuses the same MatchData instance through all matches
(this saves instantiations). If that were the case it would not make much
sense marshalling a MatchData instance. Instead one should probably
convert it into an array.

Just my 5eurocent…

robert

I didn’t really want to store them, I was just mucking around, so I’m
not going to argue on practical grounds. However, Matchdata offer
useful properties: the string that was searched, the pre- and
post-matches.

I imagine there is some optimisation going on behind the scenes:
MatchData#string returns a frozen String, so it can certainly be
shared among many MatchData objects. #pre_match appears to return a
copy of the pre-match, as modifiying its return value does not affect
subsequent calls.

All academic, anyway…

Gavin

···

On Wednesday, August 6, 2003, 7:42:01 PM, Robert wrote:

Maybe a Regexp reuses the same MatchData instance through all matches
(this saves instantiations). If that were the case it would not make much
sense marshalling a MatchData instance. Instead one should probably
convert it into an array.