Take a look at this code:
class Person
attr_reader :name
def initialize( name )
puts "Initializing Person instance #{object_id}"
@name = name
end
def greet( name )
puts "Hi #{name}, I'm #{name()}"
end
end
When you wrote initializewithout an explicit recipient:
initialize( "ak" )
It was only lucky that your message was recognized. See who answered:
method( :initialize ).owner
BasicObject, the nickname of all instances Object, she answered your call herself, scolding you for the wrong number of arguments, because:
method( :initialize ).arity
, . , #initialize , . Class#new Person#initialize :
A = Person.new( 'Abhinay' )
Initializing Person instance -605867998
Person.new #initialize. , #initialize , . magic. Person#initialize :
A.initialize( 'Fred' )
NoMethodError: private method `initialize' called for #<Person:0xb7c66044 @name="Abhinay">
"", . , :
A.greet "Arup"
Hi Arup, I'm Abhinay