Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why ENV behave like a hash, but it's an Object class

Tags:

ruby

Am I right to consider ENV a Hash

ENV['HOME']

=>'/Users/yozloy'

But

ENV.class

#=>Object
like image 768
mko Avatar asked Feb 24 '23 12:02

mko


1 Answers

It implements most of the Hash methods but apparently a few are missing:

[:default, :default=, :default_proc, :default_proc=, :merge!, :merge, :flatten, :compare_by_identity, :compare_by_identity?]

Most of these you'd never think to use, but merge and flatten could be useful.

Remember that ENV isn't exactly a Hash, but a wrapper around the environment variables and the associated methods for retrieving and setting them.

like image 200
tadman Avatar answered Mar 16 '23 12:03

tadman