Ruby constant lookup: The good, the bad and the ugly - makandropedia

makandra cards makandropedia Cards Topics Welcome, guest Sign up Sign in About makandra cards « back to all cards in this deck Posted about 1 year ago. Visible to the public. Repeats. In Ruby, classes and modules are called constants . This card explains how Ruby resolves the meaning of a constant. E. g. in the following example, Array could mean either Foo::Array or simply Array : class Foo def list Array.new end end What Ruby does here is to see if the name Array makes sense inside of Foo:: , and if that fails, resolves it to ::Array (without a namespace). You might be surprised that these are all valid ways to reference Ruby's String class: String Array::String Array::Hash::String When you see Array::String , do not think "a class String inside the Array namespace". Rather think: "What does String resolve to from the vi...

Linked on 2014-12-19 03:13:54 | Similar Links