Using ObjectSpace to locate the Chef::Node instance in a library


#1

What are your thoughts about doing something like this in a Chef library to get access to the Chef::Node instance early in the compile phase?

node = ObjectSpace.each_object(Chef::Node).to_a.first

#2

if you’re using ObjectSpace for anything other than debugging memory leaks, it’s probably a bad idea. Chef provides you with Chef.node for this purpose: https://github.com/chef/chef/blob/master/lib/chef/chef_class.rb


#3

Ah… that is SO much better. Thank you