Explain me what is the difference between Symbol and String?
Submitted by: Muhammad☛ The symbol in Ruby on rails act the same way as the string but the difference is in their behaviors that are opposite to each other.
☛ The difference remains in the object_id, memory and process time for both of them when used together at one time.
☛ Strings are considered as mutable objects. Whereas, symbols, belongs to the category of immutable.
☛ Strings objects are mutable so that it takes only the assignments to change the object information. Whereas, information of, immutable objects gets overwritten.
☛ String objects are written like
p: “string object jack”.object_id #=>2250 or
p: “string object jack”.to_sym.object_id #=> 2260, and
p: “string object jack”. to_s_object_id #=> 2270
☛ Symbols are used to show the values for the actions like equality or non-equality to test the symbols faster then the string values.
Submitted by: Muhammad
☛ The difference remains in the object_id, memory and process time for both of them when used together at one time.
☛ Strings are considered as mutable objects. Whereas, symbols, belongs to the category of immutable.
☛ Strings objects are mutable so that it takes only the assignments to change the object information. Whereas, information of, immutable objects gets overwritten.
☛ String objects are written like
p: “string object jack”.object_id #=>2250 or
p: “string object jack”.to_sym.object_id #=> 2260, and
p: “string object jack”. to_s_object_id #=> 2270
☛ Symbols are used to show the values for the actions like equality or non-equality to test the symbols faster then the string values.
Submitted by: Muhammad
Read Online Ruby Developer Job Interview Questions And Answers
Top Ruby Developer Questions
☺ | Tell us what is class libraries in Ruby? |
☺ | Tell me can you call a private method outside a Ruby class using its object? |
☺ | Explain me what is the function of ORM in Ruby on Rails? |
☺ | Tell me the role of modules and mixins in Ruby? |
☺ | What is the difference extend and include? |
Top Web Developer Categories
☺ | Bootstrap Interview Questions. |
☺ | Front End Web Developer Interview Questions. |
☺ | Typography Interview Questions. |
☺ | Laravel PHP Developer Interview Questions. |
☺ | Junior Developer PHP Interview Questions. |