Object oriented programming 2 Flashcards
Why are private methods used?
To make sure external users can’t accesses or harm your software.
What do private methods do?
They make sure that the method can’t be called from outside the class.
What is a public method?
A public method is a method that can be called from outside the class. All methods are public by default in ruby.
What is the attr_reader used for?
It is used for accessing a variable in a method/class
what is the attr_writer used for?
It’s used for changing the variable in the method/class
What is the attr_accessor used for?
It is used as bot a attr_reader and attr_writer.
What is an module in Ruby?
A module is like a class, but it can’t create instances or have subclasses.
Modules are good when using constants, because constants don’t change, but variables do.
How do you write a module?
module ModuleName # Bits 'n pieces end
How do you write constants in ruby?
You write them in ALL_CAPS
like PI
What is namespacing?
The main purpose of a module is to separate methods and constants into named spaces, and this is called namespacing.
What is the scope resolution operator?
It is used for telling ruby where to look for something.
Math : : PI means that Ruby should look for the PI inside the Math module.
What is require?
When the interpreter doesn’t have a module you need to bring it in with require. It basically runs another file.
require ‘module’
What is include?
The include method takes all the methods from one module and includes them in the current method.
What is mixin?
Mixin is when you blend additional behaviour from a module into a class. Meaning that we can customise a class whit out writing new code.
What is the extend keyword?
The extend keyword means that the class can use the methods as opposed to the instance of the class.