From the course: Complete Guide to Ruby
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Class attributes - Ruby Tutorial
From the course: Complete Guide to Ruby
Class attributes
- [Instructor] In this movie, we will learn how to define and use class attributes. Class attributes are properties that are related to a class generally, not to a specific instance. It's the same idea as we saw with class methods in the last movie. Class attributes will define shared values among all instances of the class. A class variable is recognizable because it has two @ signs at the start, where an instance variable only has one. This communicates that the variable has scope throughout every instance of the class. Any instance of the class can access it, it's like a shared variable. A class variable can be defined anywhere inside the class definition. It does not have to be inside a method. In this example, wheels is a class variable that's set to 2. There's also an instance variable for color that gets set whenever an object is initialized. Notice that the description instance method is able to access both the instance variable and the class variable. All instances that are…
Download courses and learn on the go
Watch courses on your mobile device without an internet connection. Download courses using your iOS or Android LinkedIn Learning app.
Contents
-
-
(Locked)
Objects2m 30s
-
Variables3m 26s
-
(Locked)
Numbers: Integers3m 46s
-
(Locked)
Numbers: Floats4m 4s
-
(Locked)
Strings5m 34s
-
(Locked)
Strings: Escaping and interpolation5m 36s
-
(Locked)
Arrays5m 35s
-
Array methods6m 59s
-
(Locked)
Hashes5m 2s
-
(Locked)
Symbols5m 41s
-
(Locked)
Booleans5m 29s
-
(Locked)
Ranges5m 16s
-
(Locked)
Constants2m 53s
-
(Locked)
Nil2m 57s
-
(Locked)
Challenge: Roman numerals1m 2s
-
(Locked)
Solution: Roman numerals1m 19s
-
(Locked)
-
-
(Locked)
About control structures1m 27s
-
Conditionals: if, else, elsif4m 38s
-
(Locked)
Conditionals: unless3m 1s
-
(Locked)
Conditionals: case5m 5s
-
(Locked)
Conditionals: Shorthand operators6m 16s
-
(Locked)
Loops5m 36s
-
Iterators6m 39s
-
(Locked)
Challenge: Blanket patterns1m 41s
-
(Locked)
Solution: Blanket patterns7m 16s
-
(Locked)
-
-
(Locked)
Define and call methods4m 28s
-
(Locked)
Variable scope3m 36s
-
Arguments5m 46s
-
(Locked)
Argument default values3m 48s
-
(Locked)
Using a hash of options3m 38s
-
(Locked)
Return value3m 56s
-
Return multiple values3m 43s
-
(Locked)
Output vs. return values2m 47s
-
(Locked)
Challenge: Pig Latin2m 32s
-
(Locked)
Solution: Pig Latin8m 12s
-
(Locked)
-
-
(Locked)
Access files3m 16s
-
(Locked)
Write to files3m 44s
-
(Locked)
Read from files5m 18s
-
(Locked)
File pointer4m 23s
-
(Locked)
Read or write an entire file5m 20s
-
(Locked)
Rename, delete, copy3m 23s
-
(Locked)
Examine file details4m 19s
-
(Locked)
Challenge: List maker6m 25s
-
(Locked)
Solution: List maker5m 23s
-
(Locked)