Ruby Flashcards
What are the three types of access levels in Ruby classes?
public, protected and private
How would you describe methods with private access level?
They can be accessed only in the current instance
What is the difference between each and map methods?
Each will iterate over the collection and return the original array. Map will return the modified array but it will not change the original one.
What is the result of
test
What is the result of a = false || 1
1
How many types of variables are used in Ruby?
Four. Class, instance, global and local variables.
How do you cast variable type?
By using standard methods like to_i
or to_s
.
What is the result of a = true and false
a = true
How do you catch an exception in a method?
By wrapping the method body in begin
and rescue
clauses.
What does super
method do?
Invokes the same method from the parent class.
What are the values that evaluate to false
?
nil
and false
How can a variable be made immutable?
By calling .freeze
on it.
Is Ruby a statically typed or a dynamically typed language?
Dynamically typed.
What does self
mean?
self
references to the instance of the class or to the class itself.