13-01-2022
183 words
1
minute
continuing with classes
Initialize is run at object's instantiation of class x
def and class are scope gates
def or class are different scopes
thus, each variable has its own specific scope
variables within a specific scope cannot be accesed beyond that scope
- there are regular variables
- constants
- method variables, named after the class
- instance variables like @name, @colour, etc
variable scope defines what other objects can see ( and interact ) with them
instance variables
- only exist within the class definition
- @hanger is local to the blueprint only, and can be used within method
local variables
- exist in the main process
- exists in conditional branches
- HOWEVER if the object is instantiated in a non-executed conditional branch, the object will not exist later
- the programme will recognise the name, but its value will be set to nil
- ( is this like declaring variables at the start in C, but never using them)