[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

how to keep hash sort from YAML

dave

5/14/2005 8:26:00 PM


how can I cast a YAML hash data into a ruby obj without
any auto-sort feature?
---
2: 1
1: 2
3: 3

=> {1=> 2, 2=>1, 3=>3} # no, thanks
=> {2=> 1, 1=>2, 3=>3} # yes!

tnx!

--
>here are more things in heaven and earth,
horatio, than are dreamt of in your philosophy.


6 Answers

James Gray

5/14/2005 8:30:00 PM

0

On May 14, 2005, at 3:26 PM, dave wrote:

>
> how can I cast a YAML hash data into a ruby obj without
> any auto-sort feature?
> ---
> 2: 1
> 1: 2
> 3: 3
>
> => {1=> 2, 2=>1, 3=>3} # no, thanks
> => {2=> 1, 1=>2, 3=>3} # yes!

Hashes are unordered by definition. You have no control over how
Ruby stores and returns the pairs. If you need an ordered data
structure, use an Array.

Hope that helps.

James Edward Gray II



dave

5/14/2005 8:51:00 PM

0


> Hashes are unordered by definition.  
> You have no control over how  
> Ruby stores and returns the pairs.

I would report to the user hashes in the same order they were
written in yaml by the user.

> If you need an ordered data structure, use an Array.

I must handle hashes too.


--
>here are more things in heaven and earth,
horatio, than are dreamt of in your philosophy.


why the lucky stiff

5/14/2005 9:45:00 PM

0

dave wrote:

>how can I cast a YAML hash data into a ruby obj without
>any auto-sort feature?
>---
>2: 1
>1: 2
>3: 3
>
>
James is correct. Neither Ruby nor YAML allows hashes to be ordered.
However, Ruby's YAML library includes an Omap type[1], which acts like
the ordered dictionaries you'll find in PHP.

A basic demonstration:

>> require 'yaml'
=> true
>> omap = YAML::Omap['c', 1, 'a', 2, 'b', 3]
=> [["c", 1], ["a", 2], ["b", 3]]
>> y omap
--- !omap
- c: 1
- a: 2
- b: 3

As you can see, the Omap is just an array that contains hash pairs. You
can use the Omap in Ruby just like a Hash.

>> omap2 = YAML::load( YAML::dump( omap ) )
=> [["c", 1], ["a", 2], ["b", 3]]
>> omap2.each { |k,v| p [k,v] }
["c", 1]
["a", 2]
["b", 3]

_why
[1] http://yaml.org/type...



dave

5/14/2005 10:32:00 PM

0


> As you can see, the Omap is just an array that contains hash pairs.  You
> can use the Omap in Ruby just like a Hash.

thank you all, i'm now able to better understand the problem (and the
solution).

--
>here are more things in heaven and earth,
horatio, than are dreamt of in your philosophy.


Potac Hammerfist

7/15/2013 12:30:00 AM

0

In article <8d09ad8b-343d-4ad6-9e77-d7eaee8097c2@googlegroups.com>,
blackheart666_2000@yahoo.com says...
> On Sunday, July 14, 2013 6:47:30 AM UTC-4, Moramarth wrote:
> > On Sunday, July 14, 2013 10:26:47 AM UTC+1, Playa wrote:
> >
> > > Hey,
> >
> > >
> >
> > >
> >
> > >
> >
> > > Word is, the 40kA2 Martyr LEGO Blocks are ... unusual for GW.
> >
> > >
> >
> > >
> >
> > > Also, someone twists the bits off the sprue for you?
> >
> > >
> >
> > >
> >
> > >
> >
> > > http://s2.postimg.org/xiz0omvuh/A1_No...
> >
> > >
> >
> > >
> >
> > >
> >
> > > Then, the bits are scraped into ziploc baggies?
> >
> > >
> >
> > >
> >
> > >
> >
> > > http://s21.postimg.org/wcb2yey6f/A2_Zi...
> >
> > >
> >
> > > Ime, sprue divots and pre-twisted bits are youngblood mistakes.
> >
> > >
> >
> > > Can anyone confirm that this insanity isn't an interweb hoax?
> >
> > >
> >
> > Well, it's not a first for GW - I picked up "Dreadstone Blight" when it came out a few years back and it was bits in bags. The bits are still in the bags, so I don't know about glueability (it's awaiting the "Wheel of Winds" in the basement to be replaced by a "Pool of Something" - priority No.1597...).
> >
>
> The Wizard Tower also comes in a bag. Not sure about the watchtower. I have a feeling that the Astromancer Lair comes in a bag as well, but I have not gotten around to getting one.
>
> My Wizards Tower and Dreadstone Blight did not have sprue marks or anything of the sort. Regardless, it's not the packaging trolls job to clean it up, their job is to get it into the package.
>
> It's entirely possible that the pictures that Playa posted are real, but the accounts of horror have more than likely been sweetened with typical internet hyperbole and faggotry by the same sad sods that spend all of their moms credit limit at Games workshop and then cry about it all night on Dakka.
>
Would you like me to post the large collection of 'real' failcast pics
both old and new? Or would you like to accept that GW of late has been
looking ever harder at ways to cut down production costs while
increasing price even when it means lowering quality. Failcast was a
debacle from start to finish and continues to have a sub-par reputation
among those who buy it and independant retailers who deal with all the
complaints and don't have to suck the corporate dick and smile while
lying about the quality. If the new fortifications are resin rather
than plastic, I'm even less interested than I was when I first saw their
prices.

It's one thing to point out that GW controls the IP for 40K and WFB -
it's quite another to argue that Corporate gives a shit about the player
base in any meaningful way beyond "How deep do you think their pockets
go?"

Myrmidon

--
"I'm already impoverished from buying wargames minis,
and I'm too knackered for riotous living..."

-- Moramarth

RGMW FAQ: http://ww...

Blackheart

7/15/2013 5:02:00 AM

0

On Sunday, July 14, 2013 8:30:25 PM UTC-4, Myrmidon wrote:

>
> Would you like me to post the large collection of 'real' failcast pics
>
> both old and new? Or would you like to accept that GW of late has been
>
> looking ever harder at ways to cut down production costs while
>
> increasing price even when it means lowering quality. Failcast was a
>
> debacle from start to finish and continues to have a sub-par reputation
>
> among those who buy it and independant retailers who deal with all the
>
> complaints and don't have to suck the corporate dick and smile while
>
> lying about the quality. If the new fortifications are resin rather
>
> than plastic, I'm even less interested than I was when I first saw their
>
> prices.
>

You don't need to. I well aware that Finecast didn't go so well at the start. I returned more than a couple of the models I got at the beginning for replacements. They got replaced with models that were fine, just like GW has always replaced bad models, or kits that were missing parts. Are there still Finecast models that are miscast? yup. are there still kits that are missing parts? yup. They get fixed.

Anyway.. the fortifications aren't resin. They're plastic. They're off the sprue to get them into a smaller box.

>
>
> It's one thing to point out that GW controls the IP for 40K and WFB -
>
> it's quite another to argue that Corporate gives a shit about the player
>
> base in any meaningful way beyond "How deep do you think their pockets
>
> go?"
>
>

So you're saying that Games Workshop is a corporate entity? Hold the fucking presses, we've got a major story here... no wait... no we don't... If you think that there is *any* publicly traded corporate entity (or any corporate entity at all) that gives a wet fart about you, me or anyone else beyond "How deep do you think their pockets go?" then you are beyond sadly mistaken, and I'd be terribly disappointed in you because I know you're a smarter dude than that.

Do you think the company you work for gives a shit about you?

Do you really think that Privateer or any other game company gives a shit about you?

Nowhere have I claimed that GW cares, in fact, that's the entire point I've been trying to fucking get thru peoples heads. GW does not care. They do not care because they know that the people crying the loudest are the people that still give them every. last. penny.

Tom Kirby sails off with the money. Game over. Because the people that give him their (parents) money are addicts and they can't kick the habit. All of those other guys? They're sailing off with less of the money, but they know that as long as they stay ten steps behind Kirby, no one's going to notice them.

It's toy soldiers. It's as serious as you take it. Good night.