Whats the difference between symbol and string?

Answer Posted / abhishek shukla

Symbol refers to the same memory location where string
generates a new id every time for eg.

STRING
irb(main):019:0> "ruby".object_id
=> 24095860
irb(main):020:0> "ruby".object_id
=> 24092310
irb(main):021:0> "ruby".object_id
=> 24088760
irb(main):022:0>

SYMBOL
irb(main):022:0> :ruby.object_id
=> 102978
irb(main):023:0> :ruby.object_id
=> 102978
irb(main):024:0> :ruby.object_id
=> 102978
irb(main):025:0> :ruby.object_id
=> 102978
irb(main):026:0>

Is This Answer Correct ?    23 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is the difference between destroy and delete?

517


How are the key differences between python and ruby?

492


Explain the controller in rails?

477


how you can run Rails application without creating databases?

456


Explain unobtrusive javascript in rails.

495






What is the latest version of ruby on rails?

506


Write a program to show the functionality of request.xhr in ruby on rails ?

486


Is ruby on rails popular?

509


explain request/response cycle?

534


What is the purpose of auto_load in ruby?

501


When are self.up and self.down methods used?

502


what is Mixin in Rails?

532


How to serialize data with yaml?

519


what is the purpose of the resources method in the code snippet below?

480


What are the different components of rails ?

508