Whats the difference between symbol and string?
Answers were Sorted based on User's Feedback
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 |
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 |
What is the architecture of Model views and controllers
What are the three methods to install ruby on rails?
What is the purpose of auto_load in ruby?
What are the different components of rails ?
what is the log that has to seen to check for an error in ruby rails?
What is difference between form_for and form_tag?
what is the difference between calling super() and super call?
Explain me what is the naming convention in rails?
what is the difference in scope for these two variables: @@name and @name?
How to use two databases into a single application?
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?
Explain how does rails implement ajax?