Hash Problem .. + Urgent

Hi Guyz,

Problem with me is that whenever i am storing values in my hash… it
stores perfectly …

But when i am trying to print it … i mean try to view its contents …
then contents coming in wrong order … which i dont want …

Can sum one help me bit about it … ?

Hashes won’t keep the insertion order in Ruby (or any other language,
you’ll usually have to use some kind of ordered hash).

Maurício Linhares
http://codeshooter.wordpress.com/ | http://twitter.com/mauriciojr

On Wed, Jul 22, 2009 at 9:23 AM, Hemant

So no solution … is it … ?

Maurício Linhares wrote:

Hashes won’t keep the insertion order in Ruby (or any other language,
you’ll usually have to use some kind of ordered hash).

Maur�cio Linhares
http://codeshooter.wordpress.com/ | http://twitter.com/mauriciojr

On Wed, Jul 22, 2009 at 9:23 AM, Hemant

http://loopkid.net/articles/2008/06/19/ordered-hashes-in-ruby-1-8

Maurício Linhares
http://codeshooter.wordpress.com/ | http://twitter.com/mauriciojr

On Wed, Jul 22, 2009 at 9:29 AM, Hemant

But i remember i had done it in Perl … So y not with ruby …

Hemant B. wrote:

So no solution … is it … ?

Maurício Linhares wrote:

Hashes won’t keep the insertion order in Ruby (or any other language,
you’ll usually have to use some kind of ordered hash).

Maur�cio Linhares
http://codeshooter.wordpress.com/ | http://twitter.com/mauriciojr

On Wed, Jul 22, 2009 at 9:23 AM, Hemant

Hi –

On Wed, 22 Jul 2009, Hemant B. wrote:

So no solution … is it … ?

Hashes in Ruby 1.9 are ordered by key insertion order.

David


David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Now available: The Well-Grounded Rubyist (The Well-Grounded Rubyist)
Training! Intro to Ruby, with Black & Kastner, September 14-17
(More info: http://rubyurl.com/vmzN)

No i dont think so …
The way i am inserting values in hash is not d way i am getting these
values …

David A. Black wrote:

Hi –

On Wed, 22 Jul 2009, Hemant B. wrote:

So no solution … is it … ?

Hashes in Ruby 1.9 are ordered by key insertion order.

David


David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Now available: The Well-Grounded Rubyist (The Well-Grounded Rubyist)
Training! Intro to Ruby, with Black & Kastner, September 14-17
(More info: http://rubyurl.com/vmzN)

By d way champs … where to write the code for require ‘file’ … ? in
layouts file or in same file … or in controller or in model … :slight_smile:

Conrad T. wrote:

2009/7/22 Maurício Linhares [email protected]

Hashes won’t keep the insertion order in Ruby (or any other language,
you’ll usually have to use some kind of ordered hash).

Maurício Linhares
http://codeshooter.wordpress.com/ | http://twitter.com/mauriciojr

This isn’t true because the insertion order is maintained in Ruby 1.9.1
as well as Smalltalk.

-Conrad

Hi –

On Wed, 22 Jul 2009, Hemant B. wrote:

No i dont think so …
The way i am inserting values in hash is not d way i am getting these
values …

Then you’re not using Ruby 1.9 :slight_smile:

David


David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Now available: The Well-Grounded Rubyist (The Well-Grounded Rubyist)
Training! Intro to Ruby, with Black & Kastner, September 14-17
(More info: http://rubyurl.com/vmzN)

2009/7/22 Maurício Linhares [email protected]

Hashes won’t keep the insertion order in Ruby (or any other language,
you’ll usually have to use some kind of ordered hash).

Maurício Linhares
http://codeshooter.wordpress.com/ | http://twitter.com/mauriciojr

This isn’t true because the insertion order is maintained in Ruby 1.9.1
as well as Smalltalk.

-Conrad