[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

[YAML] what happened to :SortKeys option to #to_yaml?

Joel VanderWerf

2/3/2006 8:06:00 PM


I think this used to produce sorted output in 1.8.2:

irb(main):002:0> h = {}
=> {}
irb(main):003:0> 10.times {|i| h[i] = i}
=> 10
irb(main):004:0> puts h.to_yaml(:SortKeys => true)
---
5: 5
0: 0
6: 6
1: 1
7: 7
2: 2
8: 8
3: 3
9: 9
4: 4
=> nil

Is there still a way to do this?

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


4 Answers

Ara.T.Howard

2/3/2006 9:50:00 PM

0

Joel VanderWerf

2/3/2006 10:07:00 PM

0

ara.t.howard@noaa.gov wrote:
> On Sat, 4 Feb 2006, Joel VanderWerf wrote:
>
>>
>> I think this used to produce sorted output in 1.8.2:
>>
>> irb(main):002:0> h = {}
>> => {}
>> irb(main):003:0> 10.times {|i| h[i] = i}
>> => 10
>> irb(main):004:0> puts h.to_yaml(:SortKeys => true)
>> ---
>> 5: 5
>> 0: 0
>> 6: 6
>> 1: 1
>> 7: 7
>> 2: 2
>> 8: 8
>> 3: 3
>> 9: 9
>> 4: 4
>> => nil
>>
>> Is there still a way to do this?
>
> i just happened to be working on this today
>
> jib:~/eg/ruby/alib/alib-0.3.1 > cat a.rb
> require "alib"
>
> oh = ALib::OrderedHash::new
>
> ("a".."z").to_a.reverse.each{|x| oh[x] = x}
>
> oh.yaml_inline!
>
> y oh
>
>
> jib:~/eg/ruby/alib/alib-0.3.1 > RUBYLIB=./lib ruby a.rb
> --- { z: z, y: y, x: x, w: w, v: v, u: u, t: t, s: s, r: r, q: q, p:
> p, o: o, n: n, m: m, l: l, k: k, j: j, i: i, h: h, g: g, f: f, e: e, d:
> d, c: c, b: b, a: a }
>
>
> the class is in alib now, but the yaml_inline will break on 1.8.4.
> releasing soon.
>
> cheers.
>
>
> -a
>

Not quite the same, is it?

I don't want to preserve the order in which I add keys. I just want the
YAML output to be sorted by key.

Also, I want the old behavior of :SortKeys, which was to do this
recursively to all hashes hanging off the object you call #to_yaml on.

This is mostly for aesthetic reasons (and being able to find keys in the
output doc).

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


Ara.T.Howard

2/3/2006 10:19:00 PM

0

Bill Steele

7/23/2009 6:15:00 PM

0

In article
<a15d2e2d-a30e-400f-b21f-af3e5d383a3f@r2g2000yqm.googlegroups.com>,
Clay <clays0nline@gmail.com> wrote:

> On Jul 22, 1:05?pm, "Lamont Sanford" displays stupidity again <LOL>:
> ...
>
> > Clay wrote:
> > > Dow = 8915.94 UP 67.79
> > > NASDAQ = 1916.20 UP 6.91
> >
> > > --------------------
> >
> > > If the DOW & NASDAQ are doing this upward dance in a year
> > > and three
> > > months from now... Obama & the Democrats will have another
> > > blow-out
> > > year.
> >
> > > 62, 63 or 65 Democrat senators is not out of the question.
> >
> > > -C-
> >
> > It's not luck.
>
> Of course it's luck, you moron.
>
> What else could it be?
>
> *sigh*
>
> -C-

Lots of things: A natural business cycle, rising confidence based on the
belief that the Stimulus will work, or actual effect of the Stimulus.
(The last unlikely because it's too soon.)

But the election won't be about the stock market. The question is, wil
the rising market lead to easier credit, more home sales, more business
expansion and jobs? Probably, but will it come soon enough?