Forum: Ruby on Rails typecasting 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.
onurturgay (Guest)
on 2005-12-03 13:50
(Received via mailing list)
I want to typecast an object of HashWithIndifferentAccess (params) to
Hash.
Whats the way of doing this (except each?)

Thanks in advance.
sstephenson (Guest)
on 2005-12-03 20:30
(Received via mailing list)
Hi,

On 12/3/05, Onur T. <removed_email_address@domain.invalid> wrote:
> I want to typecast an object of HashWithIndifferentAccess (params) to Hash.
> Whats the way of doing this (except each?)

There is no typecasting in Ruby.  The Hash.[] method returns a new
Hash from the object you pass in:

  params[:action] # => 'index'
  params.class # => HashWithIndifferentAccess

  strict_params = Hash[params]

  strict_params.class # => Hash
  strict_params[:action] # => nil
  strict_params['action'] # => 'index'

Sam
This topic is locked and can not be replied to.