Hello one Welcome to this lecture hall in this lecture I'll be explaining what symbols are in the Ruby
programming language.
What is a symbol.
A symbol can be characterized by a variety of properties.
You can think of a thimble as a label used to identify a piece of data.
Also he symbol is only stored once in memory.
A symbol is like a variable name.
But it is prefixed with a colon.
I've got an example an example is an action that is a symbol.
Green on the score Fritz.
You don't have to pre declare symbol and be guaranteed to be unique.
So the symbol is unique throughout the program.
Also there is no need to sign some kind of value to this symbol because Ruby takes care of that for
you.
Ruby guarantees that no matter where it appears in your program a particular symbol will have the same
value it makes it unique.
A symbol in a way is kind of like in name and an internal idea in name that has an internal eidy symbol
is quite useful because a given thing born in refers to the same object Truthout the Ruby program.
I've already mentioned that it is unique.
Symbols are also more efficient than strings.
For example two strings with the same content are two different objects.
However any given name there is only one thing one object.
The symbol object is unique.
This is important because it makes it more efficient both in time and memory.
So I'll be showing you an illustration of this shortly.
So when do you decide to use a streak or a symbol.
If you're not sure what decisions to make than to use a string more this symbol.
If the content that is the sequence of the characters of the object they are important then use a string.
If however the identity of the object is more important I would advise you use the symbol.
Ruby uses symbols and also maintains he symbol table that holds all the symbols symbols are basically
names and names of instances of variables names of methods names of classes.
So there is a method.
Any method you create for example if there's a method called quantrill underscore movie there is automatically
a symbol created for that.
Let me illustrate the key differences between using a String and a symbol.
So I went to start with a string.
First good to display so are typing posts followed by quirts under a string.
Do a dot dot it.
This would give me the idea I want a score Heidi Precentor notice is giving me a value.
5 Do the same thing again.
It'll give me a different value on time since Trink
again.
Same thing dot objet on the score Heidi breath.
And to note is given a different Heidi this time same.
Same content different ideas each time and that uses memory.
So is a waste of memory space in comparison with a thimble.
So let me do a thimble this time.
This is a symbol PUDs.
When you do a symbol you have to do it he signed the call on to indicate that that is his symbol.
Okay then type in symbol.
There are no quotes because it's a symbol you only put quotes around strings.
So I do the same object on this score Heidi
and press enter.
Notice the value I've got if I do the same thing again.
I should get the same value for the symbol the symbol loosemore.
Got
huggett on the score.
I'd be a presenter keynote is I've got the same value.
So you can see that the symbols are actually more efficient than strings fit for this leg.
So this was just a brief illustration to explain what is symbolics the key difference in comparison
to his string.
If you want to know more please just go to the ruby documentation on the ruby website and you can read
more about symbol.
Thanks so much for watching.
Bye for now.