Reputation: 65
I have ruby script as follows:
class Person
def initialize(name)
@name = name
end
def aMethod()
puts "Excecuting aMethod"
end
end
class Employee < Person
end
e1 = Employee.new("Salunke")
e1.id
after the execution of above script im getting following error:
first.rb:16: warning: Object#id will be deprecated; use Object#object_id
how to resolve above warning/error?
Upvotes: 0
Views: 99
Reputation: 2463
Problem is: There is an id
method on class Object
, but thats probably not the kind of id you want. It's the object-id of your employee instance generated by the ruby vm . Since thats a pretty common mistake, the id
method got deprecated in favour of the more concise object_id
. You would have to implement an id
method yourself, or, if you really want the object_id
, call that method instead of calling id
Upvotes: 0
Reputation: 1242
According to the warning:
Object#id will be deprecated; use Object#object_id
so, replace the id
with object_id
e1.object_id
Upvotes: 3
Reputation: 1610
In your example, "e1" is an instance of your class "Employee" (which extend Person)
When you invoke the method "id" (send the message "id" to the object) on the instance "e1", ruby try to call the id method on the whole chain of objects.
The main Object class didn't declare an "id" but an "object_id" method.
As Phelios pointed out, the message is clear enough.
Upvotes: 0