Saturday, March 10, 2012

Interview Question : Symbols & Strings

Question : What do you know about symbols and strings?

Well, I think both are almost same except there behaviors which are different. Which can be checked with there object_id, memory and process time.

There are 2 types of objects : mutable and immutable.
Mutable objects can be changed after assignment while immutable objects can only be overwritten.

Strings are mutable and symbols are immutable. Also symbols and strings both are considered different if we compare the process time.

This is a very short description about symbols and strings. But at Robert Sosinski blog its beautifully explained in The Difference Between Ruby Symbols and Strings. This post will take you step by step about the differences, about object_id, process time, etc.

No comments:

Post a Comment