Typecasting HashWithIndifferentAccess


#1

I want to typecast an object of HashWithIndifferentAccess (params) to
Hash.
Whats the way of doing this (except each?)

Thanks in advance.


#2

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