[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

YAML Parsing, ignoring objects?

Travis Smith

3/21/2005 6:27:00 PM

I have a class which when YAMLized produces...

--- !ruby/object:Player
name: dude
password: dude
session: !ruby/object:TCPSocket {}
thread: !ruby/object:Thread {}

I'd like to figure out a way for it to just ignore the Thread and/or
TCPSocket type. It won't choke on the socket, but it will loading up
the Thread. Can I add a domain type that will just produce nil not
matter what happens?

irb(main):019:0> YAML::add_domain_type("legomaster.net,2005-03",
/Thread/) { | type, val | nil }
=> nil
irb(main):020:0> temp = YAML.load_file('data/players/dude.o')
TypeError: allocator undefined for Thread
from /usr/local/lib/ruby/1.8/yaml.rb:347:in `allocate'
from /usr/local/lib/ruby/1.8/yaml.rb:347:in `object_maker'
from /usr/local/lib/ruby/1.8/yaml/rubytypes.rb:36
from /usr/local/lib/ruby/1.8/yaml/rubytypes.rb:34:in `call'
from (irb):20:in `transfer'
from /usr/local/lib/ruby/1.8/yaml.rb:119:in `load'
from /usr/local/lib/ruby/1.8/yaml.rb:119:in `load'
from /usr/local/lib/ruby/1.8/yaml.rb:130:in `load_file'
from /usr/local/lib/ruby/1.8/yaml.rb:129:in `open'
from /usr/local/lib/ruby/1.8/yaml.rb:129:in `load_file'
from (irb):20
irb(main):021:0>

Thanks, it would much easier if I didn't have to end up writing my own parser.

~Travis Smith


5 Answers

Florian Gross

3/21/2005 7:03:00 PM

0

Travis Smith wrote:

> I have a class which when YAMLized produces...
>
> --- !ruby/object:Player
> name: dude
> password: dude
> session: !ruby/object:TCPSocket {}
> thread: !ruby/object:Thread {}
>
> I'd like to figure out a way for it to just ignore the Thread and/or
> TCPSocket type. It won't choke on the socket, but it will loading up
> the Thread. Can I add a domain type that will just produce nil not
> matter what happens?

Perhaps you can just redefine Player#to_yaml to exclude those?

Travis Smith

3/21/2005 8:01:00 PM

0

That did it for now. We'll see if I end up screwing things up in the
future because I don't to_yaml something right.

Thanks


On Tue, 22 Mar 2005 04:04:53 +0900, Florian Gross <flgr@ccan.de> wrote:
> Travis Smith wrote:
>
> > I have a class which when YAMLized produces...
> >
> > --- !ruby/object:Player
> > name: dude
> > password: dude
> > session: !ruby/object:TCPSocket {}
> > thread: !ruby/object:Thread {}
> >
> > I'd like to figure out a way for it to just ignore the Thread and/or
> > TCPSocket type. It won't choke on the socket, but it will loading up
> > the Thread. Can I add a domain type that will just produce nil not
> > matter what happens?
>
> Perhaps you can just redefine Player#to_yaml to exclude those?
>
>


--
~Travis


why the lucky stiff

3/21/2005 8:22:00 PM

0

Travis Smith wrote:

>I have a class which when YAMLized produces...
>
>--- !ruby/object:Player
>name: dude
>password: dude
>session: !ruby/object:TCPSocket {}
>thread: !ruby/object:Thread {}
>
>I'd like to figure out a way for it to just ignore the Thread and/or
>TCPSocket type. It won't choke on the socket, but it will loading up
>the Thread. Can I add a domain type that will just produce nil not
>matter what happens?
>
>
Hey, Travis. You can define to_yaml_properties for any object, which is
simply an method which returns an array of properties you want in your
YAML doc, in the order you like.

class Player
def to_yaml_properties; ['@name', '@password']; end
end

You can read more in the docs[1]. See the section "Type Families".

_why

[1] http://yaml4r.s...



Travis Smith

3/22/2005 2:23:00 AM

0

I missed that last part on that page and it turns out that's exactly
what I want. Thanks for pointing that out. Minimal maintenance with
leaving most of the work to YAML parser.

On Tue, 22 Mar 2005 05:22:23 +0900, why the lucky stiff
<ruby-talk@whytheluckystiff.net> wrote:
> Travis Smith wrote:
>
> >I have a class which when YAMLized produces...
> >
> >--- !ruby/object:Player
> >name: dude
> >password: dude
> >session: !ruby/object:TCPSocket {}
> >thread: !ruby/object:Thread {}
> >
> >I'd like to figure out a way for it to just ignore the Thread and/or
> >TCPSocket type. It won't choke on the socket, but it will loading up
> >the Thread. Can I add a domain type that will just produce nil not
> >matter what happens?
> >
> >
> Hey, Travis. You can define to_yaml_properties for any object, which is
> simply an method which returns an array of properties you want in your
> YAML doc, in the order you like.
>
> class Player
> def to_yaml_properties; ['@name', '@password']; end
> end
>
> You can read more in the docs[1]. See the section "Type Families".
>
> _why
>
> [1] http://yaml4r.s...
>
>


--
~Travis


charles robinson

4/22/2010 6:41:00 PM

0


"charles robinson" <robinsonchazz@comcast.net> wrote in message
news:hqq40u$g1g$1@news.albasani.net...
>
> "Mark Guest" <mark.c.guest@gmail.com> wrote in message
> news:110e23fc-abb7-457a-b630-8fbfa52213a2@x3g2000yqd.googlegroups.com...
> On Apr 22, 1:00 pm, Joe Giglio <joegig...@gmail.com> wrote:
>> If anyone knows of a good guitar instructor in Atlanta, please email
>> me @ joegig...@gmail.com.
>> The student is a friend of mine & former student.
>> Thanks!
>> JoeG
>
> Hi Joe,
>
> Charlie Robinson's in Atlanta... Don't know if he's teaching.
>
> All the best,
>
> Mark Guest
> Jazz Guitar
> www.markguest.net
> www.cdbaby.com/cd/markguest
>
> Music produces a kind of pleasure which human nature cannot do
> without."
> Confucius (c.551-479 BC)
> -----------------------------------------------------------------------------------------------------------------------------
>
> Thanks for the referall. I teach if we can get our schedules to coincide.
> Otherwise there are a slew of good teachers like Sid Wolf who Tony
> mentioned working in the music stores here. Sid plays quite a bit of
> commercial music in addition to jazz so if this person is looking for an
> all around method stylisically he would be a good choice. I'll be out of
> town until next week if they are interested have they can email me, if I
> can't do it I can turn them on to others who can. Mike Kelly, Sal Gentile
> and Dave Frackenpole would be ones to check out in addition to Sid.
> Charlie
>-----------------------------------------------------------------------------------------------

P.S. If they want to check me out here is a vid:
http://www.youtube.com/watch?v=Q...

They can find a lot more by clicking on charlieguitar and going to my
YouTube site where there is a variety of things from solo guitar. (Sorry
for the typos, I'm in a rush--Later, Charlie)