Alexander Miles Alexander Miles - 2 months ago 8
Ruby Question

How to explicitly reference core classes in Ruby?

I'm working with Chef, and I have run into a situation where I need to use the Ruby

File.dirname()
class method. Problem is, Chef overloads the core class with
Chef::Resource::File
when executing code within a
ruby_block
resource. How can one explicitly reference the core namespace File class?

Answer

Prepend the class name with ::, i.e., ::File.

Comments