Whats the difference between symbol and string?

Answers were Sorted based on User's Feedback



Whats the difference between symbol and string?..

Answer / 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

Whats the difference between symbol and string?..

Answer / surekha matte

Rails makes extensive use of symbols. A symbol looks like a
variable symbols name, but it’s prefixed with a colon.
Examples of symbols include :action,:line_items, and :id.

Rails uses symbols to identify things. In particular, it
uses them as keys when naming method parameters and looking
things up in hashes. For example:
redirect_to :action => "edit", :id => params[:id]

Is This Answer Correct ?    17 Yes 1 No

Post New Answer

More Ruby on Rails Interview Questions

What do you understand by rails migration and what it can do?

0 Answers  


What is difference between form_for and form_tag?

0 Answers  


hi am b,tech 2011 passedout now am learnig ROR technology may i knw what is the feature of this one and what is the salary ranges to this i heard there is a less salaries to this technology give me valuable suggestions

0 Answers   Baidu, GTPL,


What is the difference between render and redirect?

0 Answers  


Can you list out what can rails migration do?

0 Answers  






Explain the role of sub directory app/controllers and app/helpers.

0 Answers  


How can you protect filter methods in rails?

0 Answers  


Write the command to run the migration.

0 Answers  


Which command is used to create a migration?

0 Answers  


what is Polymorphic Association in Ruby on Rails?

0 Answers  


what is testing in rails?

0 Answers  


Who designed active record in rails?

0 Answers  


Categories