G
Gavri Fernandez
Hi everyone,
From the pickaxe first edition:
"At the top level, we're executing code in the context of some
predefined object. When we define methods, we're actually creating
(private) singleton methods for this object."
Is this true? It is true that methods defined at the top-level are
defined as singleton methods of "main" - the top level object? I
thought that the methods added at the top-level are defined as private
methods of Object. (Where I learnt this from, I'm not sure).
Experimenting gave me the latter result.
prints "whoa\n" to the screen.
So is the pickaxe wrong? Or am I missing something big?
From the pickaxe first edition:
"At the top level, we're executing code in the context of some
predefined object. When we define methods, we're actually creating
(private) singleton methods for this object."
Is this true? It is true that methods defined at the top-level are
defined as singleton methods of "main" - the top level object? I
thought that the methods added at the top-level are defined as private
methods of Object. (Where I learnt this from, I'm not sure).
Experimenting gave me the latter result.
def whoa
puts "in whoa"
end
puts Object.new.private_methods.find {|x| x == "whoa"}
prints "whoa\n" to the screen.
So is the pickaxe wrong? Or am I missing something big?