Definitions Flashcards

Defining common Ruby terminology.

You may prefer our related Brainscape-certified flashcards:
1
Q

What are Variables?

A

Any plain, lowercase word is a variable in Ruby. Consist of Letters, digits and underscores.

Example: x, y, banana2 or phone_a_quail

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define Numbers.

A

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”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are Decimal Numbers?

A

Called floats in Ruby. Floats consits of numbers with a decimal place or scientific notation.

Example: 3.14, -808.08 and 12.043e-04

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are strings?

A

Strings are any sort of characters (letters, digits, punctuation) surrounded by quotes. Single and dbl quotes are used to create strings.

Example: “sealab”, ‘2021’,

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

T or F: When you enclose characters in quotes, are they stored together as a single string?

A

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.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a symbol?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What do symbols start with?

A

Start with a colon. Example: :a, :b, or :ponce_de_leon

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How are symbols used?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are Constants?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

T or F: Do constants change over time?

A

False - Constants refer to something very specific and can’t be changed after they’re set.

Example: EmpireStateBuilding = “350 5th Avenue, NYC, NY”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are Methods?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are Method Arguments?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

T or F: Can method arguments be chained?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are class methods?

A

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 )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are global variables?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are class variables?

A
Varaibles
 which begin with double at symbols are class variables. Also used to define attributes. They can also give an attribute to many related objects in Ruby. 

Example: @@x, @@y and @@i_will_eat_chunky_bacon

The double at prefix means to attribute all. Or, you think of it as a swarm of AT’s-AT’s from Star Wars, which are all commanded by Ruby. If you change a class variable not just one changes, they all change.

17
Q

What are Blocks?

A

Any code surrounded by curly braces is a block.
Example: 2.times { print “Chunky bacon!” }

You can group a set of instructions together so that they can be passed around your program.

Curly braces can also be traded for the words Do and End, which is nice if your block is longer than on line.

18
Q

What are block arguments?

A

They’re sets of varibles surrounded by pipe characters and separated by commas.
Example: |x| , |x,y| , or |up, down, all_around|

They are used at the begining of a block.
Example: { |x,y| x+y }

19
Q

What are ranges?

A

A range is two values surrounded by parentheses and separated by an ellipsis (in the form of two or three dots).

Example: (1..3) is a range, representing the numbers 1 through 3.
( ‘a’ .. ‘z’ ) is a range, representing a lowercase alphabet.

Think of it as an accordion which has been squeezed down for carrying.

Normally, only two dots are used. if a third do is used, the last value in the range is excluded.

20
Q

What is an Array?

A

An array is a list surrounded by square brackets and separated by commas.
Example: [ 1, 2, 3,] is an array of numbers.
[ ‘coat’, ‘mittens’, ‘snowboard’] is an array of strings.

Arrays are a collection of things, but it also keeps those things in a specific order.

21
Q

What are hashes?

A

A hash is a dictionary surrounded by curly braces. Dictionaries match words with their definitions. Ruby does so with arrows made from an equals sign, followed by a greater-than sign.
Example: { ‘a’ => ‘aardvark’, ‘b’ => ‘badger’ }

Second definition: A hash is a collection of key-value pairs. Similar to an Array, except that indexing is done via arbitrary keys of any object type, not an integer index. (hashes are sometimes called associated arrays.)

22
Q

What are regular expressions?

A

A regular expression (or regexp) is a set of characters surrounded by slashes.
Example: /ruby/, /[0-9]+/ and /^\d{3}-\d{4}/

Regular expressions are used to find words or patterns in text. The slashes on each side of the expression are pins. Ruby can use a regular expression to search volumes of books very quickly.

23
Q

What are Operators?

A

Operators are used to do math in Ruby or to compare things.

Example: ** ! ~ * / % + - & &laquo_space;&raquo_space; | ^ > >= < || != !~ && += -= == === .. … not and or

24
Q

What are keywords?

A

Ruby has a number of built-in words with an ingrained meaning.

Example: alias   and     BEGIN   begin   break   case    class   def     defined
do      else    elsif   END     end     ensure  false   for     if in      module  next    nil     not     or      redo    rescue  retry return  self    super   then    true    undef   unless  until   when while   yield
25
Q

What is nil?

A

Nil represents an emptiness. It is without value. It isn’t zero. Zero is a number.

26
Q

What is the double less-than sign?

A

&laquo_space;is the concatenation operator. To concatenate is to append, or add to the end. This is also a method. After adding to the end of the string.