I don't understand the Sheep = Class.new
part in the following piece of code.
module Fence
Sheep = Class.new do
def speak
"Bah."
end
end
end
def call_sheep
Fence::Sheep.new.speak
end
What exactly is it doing?
According to the documentation, Class.new
Creates a new anonymous (unnamed) class with the given superclass (or
Object
if no parameter is given).
Furthermore,
You can give a class a name by assigning the class object to a constant.
Sheep
is that constant, so your code is equivalent to:
module Fence
class Sheep
def speak
"Bah."
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With