OO Ruby Flashcards
Ruby considers all but what 2 things to be ‘truthy’.
‘false’ and ‘nil’
What is ‘truthiness’?
Truthiness means that we can use any expression in a conditional, or with logical operators, and as long as it doesn’t evaluate to false or nil, it is considered true. Note that an expression that Ruby considers true is not the same as the ‘true’ object.
What is the difference between ‘==’ and ‘equal?’
The ‘==’ method compares the two variables’ values whereas the ‘equal?’ method determines whether the two variables point to the same object.
What level are instance variables (@instance_variable) scoped at?
Object level. They are used to track individual object state, and do not cross over between objects.
This means that the instance variable is accessible in an object’s instance methods, even if it’s initialized outside of that instance method.
What happens if you try to reference an uninitialized instance variable?
You get ‘nil’
What level are class variables (@@class_variable) scoped at?
The class level. They exhibit two main behaviors:
- all objects share 1 copy of the class variable. (This also implies objects can access class variables by way of instance methods.)
- class methods can access class variables, regardless of where it’s initialized.
What is the scope of Constants?
Lexical scope
What are ‘fake operators’?
Methods disguised as operators. (ie. +, -, *, **, ==, &, )
What do ‘fake operators’ allow us to do?
We can override their functionality.