What is the main difference between using a symbol (begins with :), and
a variable?
When should we use one over another?
Thanks.
What is the main difference between using a symbol (begins with :), and
a variable?
When should we use one over another?
Thanks.
On Wed, Jul 7, 2010 at 5:51 PM, Abder-rahman Ali
[email protected] wrote:
What is the main difference between using a symbol (begins with :), and
a variable?
They are two completely different concepts:
irb(main):003:0> :test.object_id
=> 87218
irb(main):004:0> :test.object_id
=> 87218
Compare this to, for example, Strings or Arrays:
irb(main):005:0> “test”.object_id
=> -610207318
irb(main):006:0> “test”.object_id
=> -610213628
irb(main):007:0> [].object_id
=> -610222448
irb(main):008:0> [].object_id
=> -610232888
a =
you are creating a local variable that refers to . That
object could be any object, for example a Symbol:
a = :test
When should we use one over another?
I don’t think this question has any sense, as they are completely
different concepts.
Jesus.
Thanks a lot.
2010/7/7 Jesús Gabriel y Galán [email protected]
On Wed, Jul 7, 2010 at 5:51 PM, Abder-rahman Ali
[email protected] wrote:When should we use one over another?
I don’t think this question has any sense, as they are completely
different concepts.
A better question would be: Why use a symbol? Although, a quick Google
search will give some good answers.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs