Forum: Ruby on Rails what is "!map:HashWithIndifferentAccess "?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ffd881829651935d986c52d12279befb?d=identicon&s=25 Zhenning Guan (rubyernewbie)
on 2008-10-25 16:05
I read the typo migration code file 004_add_sidebars_.rb and found
these:

      Bare4Sidebar.create(:active_position=>0, :controller=>'page',
:active_config=>'--- !map:HashWithIndifferentAccess
      maximum_pages: "10"')

I'm confused what does it meaning? work for?
anyone help~
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-25 16:26
(Received via mailing list)
On 25 Oct 2008, at 15:05, Zhenning Guan wrote:

>
> I read the typo migration code file 004_add_sidebars_.rb and found
> these:
>
>      Bare4Sidebar.create(:active_position=>0, :controller=>'page',
> :active_config=>'--- !map:HashWithIndifferentAccess
>      maximum_pages: "10"')
>
> I'm confused what does it meaning? work for?

That looks like yaml serialized data.

Fred
F47bebf5f4b10b709a59310027c8f977?d=identicon&s=25 Robert Zotter (Guest)
on 2008-10-25 16:26
(Received via mailing list)
Guan,

HashWithIndifferentAccess is just like any other hash except that the
key 'somekey' will be the same as the key :somekey.

For example if you have a regular hash like the following
>> hash = Hash.new({:somekey => 'testing'})
>> hash[:somekey]
=> testing
>> hash['somekey']
=> nil

Notice how the key 'somekey' is not the same as the key :somekey

>> hash = HashWithIndifferentAccess.new({:somekey => 'testing'})
>> hash[:somekey]
=> 'testing'
>> hash['somekey']
=> 'testing'

Here the key 'somekey' and :somekey are the same.

Understand?
--
Robert Zotter
Zapient, LLC
Ruby on Rails Development and Consulting

http://www.zapient.com
http://www.fromjavatoruby.com


On Oct 25, 7:05 am, Zhenning Guan <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.