Ruby Definitions Flashcards
1
Q
Numbers
A
- an integer, aseries of digits
- can be + or -
- no commas_ use “_”
- ex: 1, 23, -10_000, -10000
- population = 12_000_000_000o
- (place holder so full answer displays)
- (place holder so full answer displays)
2
Q
Floats (Numbers)
A
- numbers with a decimal place or written in scientific notation
- ex: 3.14, -808.08, 12.043e-04, 456_000.76
- (place holder so full answer displays)
- (place holder so full answer displays)
3
Q
Strings
A
- any characters (letters, digits, punctuation) surrounded by quotes “ “ or ‘ ‘
- ex: “sealab”, “2021”, “These are great!”
- avril_quote = “He’s just a skater boy.”
- print oprah_quote
print avril_quote
print ashlee_simpson_debacle
4
Q
Symbols
A
- look like variables, but start with a colon :
- function like diet strings
- ex: :a, :b, :ponce_de_leon
- usually used in place of a string when you won’t be printing the string to the screen
- (place holder so full answer displays)
5
Q
Constants
A
- basically proper nouns
- Capitalized
- ex: Time, Array, Joe_is_Missing
- EmpireStateBuilding = “350 5th Ave, NYC, NY”
- you can just move the Empire State Building or decide it is something else
- (place holder so full answer displays)
- (place holder so full answer displays)
6
Q
Methods
A
- basically verbs
- usually attached to the end of a variable (noun) with a dot .
- front_door.open -it will open
- front_door.open.close -it will open then immediately close
- front_door.is_open? -tests to see if it is open
- (place holder so full answer displays)
- (place holder so full answer displays)
7
Q
Variables
A
- Basically a noun.
- Ex: x, y, banana 2, phone_a_quail
- Like a nickname for something used frequently.
- teddy_bear_fee = $121.08
- total = orphan_fee + teddy_bear_fee + gratuity
- (place holder so full answer displays)
8
Q
Method Arguments
A
- more instruction for the method (verb)
- kind if like the adverbs
- surrounded by parentheses, separated by commas
- ex: front_door.paint( 3, :red).dry( 30 ).close the door gets 3 coats of red paint, dries for thirty minutes and then closes
9
Q
Class methods -or- instance methods)
A
- Attached to variables abe constants (usually)
- double colon :: used instead if dot .
- ex: Door::new ( :oak ) - create a new oak door
- most often used to create things
10
Q
Global variables
A
- begin with dollar sign $
- ex: $x, $1, $chunky, $CHunKY_bACOn
- it’s like having the same dad in every house
- can be used anywhere in the program
- (place holder so full answer displays)
11
Q
Instance variables
A
- begin with the at symbol @
- often used to describe attributes like the adjective the the noun (variable)
- you might set the @width variable inside the front_door variable
- @x, @y, @the_chunkiest
- (place holder so full answer displays)
12
Q
Class variables
A
- begin with the double at symbol @@
- set attributes for many related objects
- if instance variable sets an attribute for front_door, class variable sets an attribute for all doors
- ex: @@x, @@y, @@chunkier_than_the_chunkiest
- (place holder so full answer displays)
13
Q
Blocks
A
- surrounded by curly braces { }
- group a set of instructions together
- ex: 2.times { print “Yes, I like chunky bacon!” }
- can be replaced with do and end
- ex: loop do
print “this”
print “this too.”
end - (place holder so full answer displays)
14
Q
Block arguments
A
- variables surrounded by pipe characters and separated by commas | , |
- ex: |x|, |y|, |up, down, all_around|
{ |x,y| x + y } - x and y are added together - (place holder so full answer displays)
- (place holder so full answer displays)
15
Q
Ranges
A
- two values surrounded by ( ) separated by .. or …
- .. includes the last value
- (1..3) represents 1 through 3
- (‘a’..’z’) represents a lower case alphabet
- … excludes the last value
- (0…5) represents 0 through 4
- (place holder so full answer displays)
- (place holder so full answer displays)