1
00:00:00,690 --> 00:00:08,790
Hello one Welcome to this lecture hall in this lecture I'll be explaining what symbols are in the Ruby

2
00:00:08,820 --> 00:00:10,900
programming language.

3
00:00:11,070 --> 00:00:13,330
What is a symbol.

4
00:00:13,330 --> 00:00:19,330
A symbol can be characterized by a variety of properties.

5
00:00:19,770 --> 00:00:27,500
You can think of a thimble as a label used to identify a piece of data.

6
00:00:27,870 --> 00:00:32,640
Also he symbol is only stored once in memory.

7
00:00:34,390 --> 00:00:39,860
A symbol is like a variable name.

8
00:00:40,120 --> 00:00:44,110
But it is prefixed with a colon.

9
00:00:44,560 --> 00:00:50,670
I've got an example an example is an action that is a symbol.

10
00:00:50,770 --> 00:00:53,830
Green on the score Fritz.

11
00:00:54,160 --> 00:01:00,920
You don't have to pre declare symbol and be guaranteed to be unique.

12
00:01:00,930 --> 00:01:05,490
So the symbol is unique throughout the program.

13
00:01:05,860 --> 00:01:13,900
Also there is no need to sign some kind of value to this symbol because Ruby takes care of that for

14
00:01:13,900 --> 00:01:14,530
you.

15
00:01:14,530 --> 00:01:22,150
Ruby guarantees that no matter where it appears in your program a particular symbol will have the same

16
00:01:22,150 --> 00:01:24,640
value it makes it unique.

17
00:01:25,750 --> 00:01:36,150
A symbol in a way is kind of like in name and an internal idea in name that has an internal eidy symbol

18
00:01:36,150 --> 00:01:45,180
is quite useful because a given thing born in refers to the same object Truthout the Ruby program.

19
00:01:45,180 --> 00:01:49,570
I've already mentioned that it is unique.

20
00:01:49,750 --> 00:01:56,260
Symbols are also more efficient than strings.

21
00:01:56,530 --> 00:02:03,340
For example two strings with the same content are two different objects.

22
00:02:03,560 --> 00:02:09,610
However any given name there is only one thing one object.

23
00:02:09,610 --> 00:02:12,950
The symbol object is unique.

24
00:02:13,060 --> 00:02:20,440
This is important because it makes it more efficient both in time and memory.

25
00:02:20,440 --> 00:02:24,010
So I'll be showing you an illustration of this shortly.

26
00:02:24,010 --> 00:02:30,040
So when do you decide to use a streak or a symbol.

27
00:02:30,040 --> 00:02:36,800
If you're not sure what decisions to make than to use a string more this symbol.

28
00:02:37,030 --> 00:02:45,750
If the content that is the sequence of the characters of the object they are important then use a string.

29
00:02:46,270 --> 00:02:56,680
If however the identity of the object is more important I would advise you use the symbol.

30
00:02:56,680 --> 00:03:06,890
Ruby uses symbols and also maintains he symbol table that holds all the symbols symbols are basically

31
00:03:07,000 --> 00:03:14,990
names and names of instances of variables names of methods names of classes.

32
00:03:15,050 --> 00:03:16,780
So there is a method.

33
00:03:16,780 --> 00:03:24,040
Any method you create for example if there's a method called quantrill underscore movie there is automatically

34
00:03:24,130 --> 00:03:28,210
a symbol created for that.

35
00:03:28,210 --> 00:03:36,510
Let me illustrate the key differences between using a String and a symbol.

36
00:03:36,610 --> 00:03:38,330
So I went to start with a string.

37
00:03:38,380 --> 00:03:48,500
First good to display so are typing posts followed by quirts under a string.

38
00:03:51,200 --> 00:03:55,340
Do a dot dot it.

39
00:03:55,370 --> 00:04:04,840
This would give me the idea I want a score Heidi Precentor notice is giving me a value.

40
00:04:05,010 --> 00:04:06,580
5 Do the same thing again.

41
00:04:06,600 --> 00:04:11,440
It'll give me a different value on time since Trink

42
00:04:14,140 --> 00:04:15,070
again.

43
00:04:15,140 --> 00:04:23,140
Same thing dot objet on the score Heidi breath.

44
00:04:23,150 --> 00:04:28,530
And to note is given a different Heidi this time same.

45
00:04:28,580 --> 00:04:35,300
Same content different ideas each time and that uses memory.

46
00:04:35,360 --> 00:04:40,850
So is a waste of memory space in comparison with a thimble.

47
00:04:40,850 --> 00:04:43,280
So let me do a thimble this time.

48
00:04:43,280 --> 00:04:46,310
This is a symbol PUDs.

49
00:04:46,910 --> 00:04:55,490
When you do a symbol you have to do it he signed the call on to indicate that that is his symbol.

50
00:04:56,390 --> 00:05:00,440
Okay then type in symbol.

51
00:05:03,700 --> 00:05:08,580
There are no quotes because it's a symbol you only put quotes around strings.

52
00:05:09,000 --> 00:05:14,450
So I do the same object on this score Heidi

53
00:05:17,420 --> 00:05:19,440
and press enter.

54
00:05:19,680 --> 00:05:23,590
Notice the value I've got if I do the same thing again.

55
00:05:24,290 --> 00:05:32,470
I should get the same value for the symbol the symbol loosemore.

56
00:05:35,960 --> 00:05:36,530
Got

57
00:05:38,900 --> 00:05:43,260
huggett on the score.

58
00:05:43,560 --> 00:05:48,170
I'd be a presenter keynote is I've got the same value.

59
00:05:48,170 --> 00:05:55,700
So you can see that the symbols are actually more efficient than strings fit for this leg.

60
00:05:55,700 --> 00:06:05,630
So this was just a brief illustration to explain what is symbolics the key difference in comparison

61
00:06:05,630 --> 00:06:07,530
to his string.

62
00:06:07,940 --> 00:06:16,610
If you want to know more please just go to the ruby documentation on the ruby website and you can read

63
00:06:16,610 --> 00:06:19,010
more about symbol.

64
00:06:19,010 --> 00:06:20,720
Thanks so much for watching.

65
00:06:20,720 --> 00:06:21,690
Bye for now.
