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

How is the model view controller framework used in ruby on rails?

468


How will be the future for ruby on rails?

473


How is dynamic scaffolding different from static scaffolding?

449


What is unit testing (in classical terms)? What is the primary technique when writing a test ?

530


Explain me what are the limits of ruby on rails?

452






What does session and cookies represent in ruby on rails?

417


what are the positive aspects of Rails?

461


What is the difference between false and nil in ruby?

450


What is the difference between save and save?

519


Do you know what is rake in rails?

460


What are the various changes between the rails version 2 and 3?

455


What is the importance of rjs?

475


what is the role of Rails Controller?

486


how you define Instance Variable, Global Variable and Class Variable in Ruby?

489


Tell me what is rails migration?

445