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

Explain about restful architecture?

463


Explain the controller in rails?

468


what are helpers and how to use helpers in ror?

520


what is the use of super function in ruby on rails?

500


Where does the start_tabnav gets informations for tabs rendering in ruby rail?

470






How you run your Rails Application without creating database ?

458


what is the difference between calling super() and super call?

492


What is the Install rail package?

509


who developed rails?

521


What is the importance of rjs?

473


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

488


What are the functions performed by rails migration?

458


What is active record in rails?

522


What is the use of the super function in ruby on rails?

451


Explain me what is the role of rails controller?

477