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

Explain me what is the role of rails controller?

0 Answers  


If you want to set up a one-to-one relationship between two models, you'll need to add belongs_to to one, and has_one to the other. How do you know which is which?

0 Answers  


what is a rails migration? Write up a short example of a simple rails migration with a table called customers, a string column called name, and a text column called description?

0 Answers  


What are filters? and how many types of filters are there in ruby

2 Answers   Baidu, TCS,


Difference between gem and plugin?

0 Answers  






What are the differences betweeen Rails 2.x and Rails 3

4 Answers   Al Larin, Baidu, CTS,


what are rails filters?

0 Answers  


Why do we use request.xhr? in rails

2 Answers   IBM,


Explain some features of nested scaffolding.

0 Answers  


What is the difference between sessions and flash?

3 Answers  


what are helpers and how to use helpers in ror?

0 Answers  


What is cross-site request forgery (csrf)? How is rails protected against it?

0 Answers  


Categories