Ruby_catch_all Flashcards
What do programmers call the exclamation point (!)?
The bang operator
What does the (!) bang operator do?
It reverses the value.
What is a method?
A method is simply a definition of an action that can be performed on an object, i.e. like the .capitalize (method) that capitalizes text.
What are Arguments?
Arguments are pieces of information that are sent to a method to be modified or used to return a specific result.
We “pass” arguments to a method when we call it.
We put arguments into the parentheses following a method. For example, 1.+(2).
What are Parameters used for?
Parameters are used when you have data outside of a method’s scope, but you need access to it within the method’s scope.
def say(words)
puts words
end
You’ll notice that there’s a (words) after say in the method definition. This is what’s called a parameter.
Argument?
Additional information that is provided to a method when it is called. We put arguments into the parentheses following a method. For example, 1.+(2).
String concatenation?
string concatenation: Combining two strings together; accomplished with the concat() method or the + operator. Example: “zig” + “zag” returns “zigzag”.
Objects?
In Ruby, and most other programming languages, we call things objects .
Methods?
In Ruby, and most other programming languages, we call things objects and the actions you can tell those things to do methods.
Class?
I’ve been saying for a bit that there are different “types” of objects, but in Ruby, the real word is class. 2.3 is of the class Float; 2 is of the class Fixnum (for fixed number - a number without a decimal); and Strings like “hello!” are of the class String.
Instance?
Here’s another term to get familiar with: instance. Every object is an instance of a class. 2.3 is an instance of the Float class; 2 is an instance of Fixnum; and “hello!” is an instance of String. If there were a class called Person then you could have instances of it called mary, bob, and sam - they are all people because they belong to the class Person, but they are instances of the class because they are specific people. You can always see what class an object is by calling the class() method on it:
Variables
Variables store objects and you can think of them like a box with a special label that can hold one thing at a time, but you can change whatever is inside that box.
What is the receiver called when dealing with methods?
The object on which a method is called. Remember that the object receives the action of the method. Some methods permanently change the receiver and some do not. The String#upcase method does not change the receiver, but the String#upcase! method does.
return value:
return value: The object that is returned by the method after it has run; what we see in IRB after the method is executed.
bang
bang: The name of the exclamation point found at the end of Ruby methods that change the receiver when they are run.