Object oriented programming 1 Flashcards
What are attributes?
Attributes are specific properties of an object.
"Matz".length # ==> 4 Matz is an object .lenght is a method 4 is an attribute
What is a class?
A class is a way to organize and produce objects with similar attributes and methods.
Basically a blueprint.
How do you write a class?
class ClassName # some code end
You use CamelCase for the class name
What is the initialize method?
The initialize method is used to boost up the class, it gives us attributes that we can start up with.
It will run every time we create the class.
What is an instance variable?
An instance variable makes the variable available in other parts of the application
What is scope of a variable?
The scope of a variable is where the variable is accessible for the rest of the program. Some variables are not accessible to other parts of the program.
What are global variables?
Variables that are available everywhere
What are local variables?
Variables that are only available inside certain methods.
How do you write instance variables?
you write them with a @
@variable_name
How do you write class variables?
You write them with two @@
@@variable_nameHow do yo wr
How do you write global variables?
1) You just define the variable outside the method or class.
2) If you are writing the global variable from inside a method or a class just write $ before the variable.
How should you create variables?
You should only create them with a limited scope so that they can only be changed from a few places.
What is inheritance?
inheritance is the process by which one class takes on the attributes and methods of another.
What is the inheritance syntax?
you use the < symbol to show the inheritance.
class DerivedClass < BaseClass # Some stuff! end
This means that DerivedClass inherits from BaseClass.
What is override?
If you want a class to not to take the attributes of the baseclass
What is the super keyword?
The super keyword is used when you want to accesses the attributes or the methods of a superclass
How do you set up a class in ruby?
class SomeName end
What is inheritance?
Inheritance means that a class has access to all methods and behaviors of another class. You use the < to show the inheritance.
What can you store in a class in ruby?
You can store both methods and data in a class.
What is the getter method in a class?
The getter method allows you to retrieve data or values from a class.
What is the setter method in a class?
The setter method allows you to set values in a class.
What is the attr_accessor?
The attr_accsessor stands for attribute accessor and is used instead of the getter and setter methods.
What does instantiation mean?
When you create a class it’s like creating a blueprint, to instantiate a class means to build the house from a blueprint. To actually use the class to create.
What is an initializer method?
An initializer method is a method that will run every time you create a new instance of a class.