All language subtitles for pragstudio-ruby-05-self (Transcribed on 27-Apr-2023 20-41-30)

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified) Download
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

We want to take a moment to show you something kind of cool.

Now it may seem a little computer science-y at this point, but a lot of folks ask about

it.

Now we're going to revisit this again later, so if it doesn't all make sense now, don't

worry about it.

Now we told you that methods are always called on an object.

In this example, we're calling the capitalize method on the movie object.

We sometimes say that the movie is an explicit receiver.

But what's up with putAs?

Well, it's a method, but we've been calling it without a receiver.

So which object are we calling it on?

Okay, I've opened up a new program file here just so we can see what's going on.

And we've seen that we can use putAs to print a string to the console.

So I'm going to use the string, who's my receiver.

And we know when we run that, we get who's my receiver.

So the question is, what is this putAs thing?

Well, it's actually a method.

In fact, the string is a parameter to that method.

And we could put the parameter in parentheses, like we've seen with other method calls.

We normally don't do that with putAs, just because it's such a common and

simple command that we can leave out the parentheses in Ruby.

But this shows us that putAs is a method.

We run that, and we get the same thing.

But the real question is, what object are we calling this method on?

So we wanna know, what is this object over here?

Because we know that every time we call a method,

there must be an object that receives that method call.

So here's the thing.

Anytime there's no object on the left-hand side,

Ruby implicitly uses an object.

That object is referenced by the variable called self.

And self always references the current object.

So anytime you don't see an explicit receiver, the thing on the left-hand side

of the dot, then there's always an implicit or default receiver.

And that receiver is the object that's referenced by the variable self.

Now self always has a value, and

it changes depending on where we are in a program.

We'll see how those change when we look at classes and methods later.

But right now, let's see what the value of self is inside of our main program.

I'm gonna have to take this off, cuz that's not gonna be valid syntax.

I can just do putS, self, that's the variable name.

If we run that, we see that self is this thing called main.

That's the name of self.

So let's see what the class of self is.

It's actually an object.

So in the top level scope of a main program like this,

Ruby automatically arranges things so that there's this global object,

referenced by self, and it's called main.

Then when we call putS,

it's automatically used as the receiver of that method call.

It's as if we typed self. right there.

Unfortunately, this won't work.

It would kinda be nice if it did from an instructional standpoint.

But if we try to run this program now,

we see that we get this error private method putS called for object.

Well, it turns out that putS is actually a private method.

And the way that Ruby enforces private methods is that we can't have an

explicit receiver for private methods.

So the takeaway here is that putS is a method.

It's actually being called on an object.

That object is stored in self, and we don't have to have an explicit receiver

because in this top level program, self is already set up for us.

Now don't let this throw you.

The important thing is that every method has been called on an object,

even if you don't see that object.

If you understand that for now, then you're set.

Yeah, and now that we know how to call some of Ruby's built-in methods,

in the next section, we'll look at how to write a method of our own.

See you then.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.