sdawes
sdawes

Reputation: 661

Ruby Object ID method not working

I am following through www.ruby-doc's tutorial on Classes and Objects, which has the code:

person = "Tim"
person.id   »   537771100
person.type »   String
person      »   "Tim"

I tried the code below:

person = "Tim"
person.id
# => NoMethodError: undefined method `id' for "Tim":String

Why does it return the error after I call id on my new variable?

Upvotes: 0

Views: 73

Answers (1)

Vasfed
Vasfed

Reputation: 18474

In recent rubies the methods are object_id and class:

person = "Tim"
person.object_id # => 66765660 (varies)
person.class     # => String

Upvotes: 4

Related Questions