Ruby Definitions Flashcards

You may prefer our related Brainscape-certified 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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Arrays

A
  • list surrounded by [ ] separated by commas ,
  • ex: [1, 2, 3] or [‘coat’, ‘mittens’, ‘snowboard’]
  • keeps those things in a specific order
  • (place holder so full answer displays)
  • (place holder so full answer displays)
17
Q

Hashes

A
  • a dictionary surrounded by { }
  • definition come after arrow =>
  • ex: {‘a’ => ‘aardvark’, ‘b’ => ‘badger’}
  • can be pleasing to search through
  • { ‘name’ => ‘Peter’, ‘profession’ => ‘lion tamer’, ‘great love’ => ‘flannel’ }
  • (place holder so full answer displays)
  • (place holder so full answer displays)
18
Q

Regular expressions -or- regexp

A
  • set of characters surrounded by slashes / /
  • ex: /ruby/, /[0-9]+/, /^\d{3}-\d{4}/
  • used to find words or patterns in text
  • it’s like control+f
  • (place holder so full answer displays)
  • (place holder so full answer displays)
19
Q

Operators

A
  • used to do math or compare things
    • ! ~ / % + - & > | ^ > >= || != =~ !~ && += -= == === .. … not and or
20
Q

Keywords

A
  • build in methods
  • do not need dot .
  • cannot be used as variables or changed
  • alias, and, BEGIN, begin, break, case, class, def, define, 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
  • (place holder so full answer displays)