difference between :label and variable

dear members,

what's the difference between :label and variable?
I saw many hashes use :label as key, which has advantages than variable
keys?

Thank you.
Maggie

Using ‘:label ’It’s more memory efficient.
For example, lets say you define a variable a=5 and symbol :b=5
Then you examine their object_id by type
a.object_id and :b.object_id .
Now you change you a= 6 :b=6
Then you will see :b still has same object_id. But the object_id of the
variable ‘a’is not the same.
If you don’t know what object_id is you can do a quick google search for
the term. Hope this helps.

···

On Thu, Oct 31, 2019 at 5:57 PM Maggie Q Roth <rothmq@gmail.com> wrote:

dear members,

what's the difference between :label and variable?
I saw many hashes use :label as key, which has advantages than variable
keys?

Thank you.
Maggie

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

A Symbol (like `:label`) is just another data type. It can be
assigned to a variable the same as a String or Integer or whatever.

# an immediate Symbol
:foo

# a variable whose value is a Symbol
x = :bar

# a hash
{
  :foo => nil,
  x => nil,
}

You get the idea.

A Symbol is supposed to represent one of the simplest data types, in
that its only value is its identity, and its only operation is
identity-comparison. (In other words :foo is always exactly equal to
:foo, and nothing else.) It doesn't support addition, or
concatenation, or iteration, etc.

However over time people have treated them like "magic strings", so
the strictness of that definition is slipping slightly.

Cheers

···

On Fri, 1 Nov 2019 at 10:58, Maggie Q Roth <rothmq@gmail.com> wrote:

dear members,

what's the difference between :label and variable?
I saw many hashes use :label as key, which has advantages than variable keys?

Thank you.
Maggie

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

--
  Matthew Kerwin
  https://matthew.kerwin.net.au/