Definitions Flashcards
Defining common Ruby terminology.
What are Variables?
Any plain, lowercase word is a variable in Ruby. Consist of Letters, digits and underscores.
Example: x, y, banana2 or phone_a_quail
Define Numbers.
Basic type of number is an integer, a series of digits which can start with a plus or minus sign.
commas are not allowed in numbers, but underscores are. “Example: population = 12_000_000”
What are Decimal Numbers?
Called floats in Ruby. Floats consits of numbers with a decimal place or scientific notation.
Example: 3.14, -808.08 and 12.043e-04
What are strings?
Strings are any sort of characters (letters, digits, punctuation) surrounded by quotes. Single and dbl quotes are used to create strings.
Example: “sealab”, ‘2021’,
T or F: When you enclose characters in quotes, are they stored together as a single string?
True - Think of a reporter jotting this down. “I’m a lot wiser,” says Avril Lavigne. “Now I know what the business is like”
avril_quote = “I’m a lot wiser. Now I know what the business is like.”
What is a symbol?
Symbols are words that look just like variables. May contain letters, digits, or underscores. But they start with a colon.
Symbols are also lighweight strings. Usually used in situations where you need a string but you won’t be printing it to the screen.
What do symbols start with?
Start with a colon. Example: :a, :b, or :ponce_de_leon
How are symbols used?
Symbols are lightweight strings. Usually used where you need a string, but you won’t be printing it to the screen.
Example: You could say a symbol is a bit easier on the computer. Like an antacid. The colon indicates the bubbles trickling up from your computer’s stomach as it digests the symbol. Sweet, sweet relief.
What are Constants?
Constants are words like variables, but constants are Capitalized. If variables are the nons of Ruby, then think of constants as the proper nouns.
Example: Time, Array or Bunny_Lake_is_Missing
T or F: Do constants change over time?
False - Constants refer to something very specific and can’t be changed after they’re set.
Example: EmpireStateBuilding = “350 5th Avenue, NYC, NY”
What are Methods?
Used to bundle one or more repeatable statements into a single unit. Begins with lowercase letter. If variables & constants are nouns, then methods are the verbs. Methods are usually attached to the end of variable and constants by a dot.
Example: front_door.open
What are Method Arguments?
Method arguments are attached to the end of a method. Generally surrounded by parentheses and separated by commas.
Example: front_door.paint( 3, :red )
This paints the front door 3 coats of red.
Methods may require more information to perfom its action. Written Example: If we want the computer to paint the door, we should provide a color as well.
T or F: Can method arguments be chained?
True -
Example: front_door.paint( 3, :red ).dry( 30 ).close()
The above paints the front door 3 coats or red, dries for 30 minutes, and closes the door. The last parentheses are normally dropped.
What are class methods?
Class methods are usually attached after variables and constants. Rather than a dot, a double colon is used. Class methods are for anything that does not deal with an individual instance of a class.
Example: Door::new( :oak )
What are global variables?
Variables which begin with a dollar sign are global. Can be referred to from anywhere in a program. Should be used sparingly.
Example: $x, $1, $chunky and $CHunKY_bACOn