Can't marshal MatchData?

G

Gavin Sinclair

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
 
B

Brian Candler

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 :)

Regards,

Brian.
 
R

Robert Klemme

Gavin Sinclair said:
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
 
G

Gavin Sinclair

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,102
Messages
2,570,645
Members
47,246
Latest member
TemekaLutz

Latest Threads

Top