Fundamentals Flashcards

Remember Ruby snytax

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

Variables

A

Any plain, lowercase word. Can consist of letters, digits, and underscores.

ex. ruby_123

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

Numbers

A

Integer or series of digits. No commas but underscores allowed.

ex. 1 or -23 or 12_000_000

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

Floats

A

Decimal Numbers or scientific notation

ex. 3.14 or 12.043e-04

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

Strings

A

Any sort of characters(letters, digits, punctuation) surrounded by quotes.

ex. “sealab” or “These cartoons are great!”

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

Symbols

A

Words that look like variables but start with a colon. Used in situations where you need a string but won’t be printing it to the screen.

Ruby responds quicker symbols then strings. (Pointers)

ex. :b or :ponce_de_leon

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

Constants

A

Words like variables but are Capitalized. Variables are nouns then Contstants are proper nouns. Contstants can’t be changes once set.

ex. Time or Bunny_Lake

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

Methods

A

Methods are verbs usually set to the end of a variable or contstant with a dot. They send a message. ! and ? Are allowed.

ex. front_door.open

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

Method Argument

A

Arguments attached to the end of a method. Usually surround by a parentheses and separated by commas and can be chained – inner tubes

ex. front_door.paint( 3, :red ) .dry( 30 ) .close()

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

Kernel Methods

A

Common methods that don’t use parentheses with arguments

ex. print “See, no dot.”

Kernel::print they are all class methods

p “See, no dot.” Also works for print

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

Class/Instant Methods

A

Rather than a dot a double colon is used after variable or constant

ex. Door: :new( :oak ) Class method is new

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

Global Variables

A

Begin with a dollar sign and good throughout your program no matter what class

ex. $1 or $chucky

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

Instant Variables

A

Begin with @ and define the attributes of something. Think @ means attribute

ex. front_door with @width

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

Class Variables

A

Double @@ used to define many related objects in a given class. @@ attribute all

ex. @@x is a class variable for all doors not just front_door

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

Blocks

A

Any code surrounded by curly braces. A group of instructions you can use “do” or “end”

Scope is all information before block.

ex. 2.times { print “yes win!” }

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

Block Arguments

A

Set of variables surrounds by pipe characters and separated by commas used at the beginning of a block. Tunnel in which variables enter the block

ex. |x,y|

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

Ranges

A

2 values surrounded by parentheses and separated by ellipsis

ex. (1..5) is 1 through 5 or (‘a’..’z’)

If 3 … Used the last range is excluded (0…5) is 0 through 4

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

Arrays

A

List surround by square brackets

ex. [1,2,5] or [‘coat’, ‘mittens’, ‘gloves’]

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

Hashes

A

Dictionary surrounds by curly braces because they can be easy to search through. Unlike an array hashes are not kept in particular order. Keys => Values

ex. { ‘a’ => ‘aardvark’, ‘b’ => ‘badger’ }

code_words[‘a’] will return aardvark

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

Regular Expressions (regexp)

A

Characters surround by slashes used to find words or patterns in text.

ex. /ruby/ or /[0-9]+/

20
Q

Operators

A
  • % &&&raquo_space; are all examples
21
Q

Keywords

A

alias end BEGIN break end are all examples use them wrong will lead to syntax error

22
Q

===

A

Triple Equals is not as strict as ==

Great for looking for a value in a range

ex. 1905 === 19895..1913

23
Q

case..when statement

A

They must be used together.

case is followed by a value which is compared to when keywords

ex. case year
when 1984
“Born.”

24
Q

Scope

A

A field of vision inside methods and blocks.
Only the names inside the method are good for it’s scope.

ex.  opus_magum = true
       def Mom
           success = opus_magum
        end
opus_magum is out of Mom scope
25
Q

new

A

Method that creates a new, blank object. It also calls the initialize method automatically.

ex. todays_wishes = Wishmaker.new

26
Q

Ruby

A

Everything is an object,

  1. You define things
  2. Then you put them into action
27
Q

: :

A

Class methods are usually called with a double colon but a period is fine as well.

ex. Elevator: :maintenance_password

28
Q

backtrace

A

When you get an error the most important aspect is the beginning

29
Q

Nil

A

Without value and it can never be “true”

Ex. plastic_cup = nil

30
Q

unless

A

Will show “nil” and “false”

The opposite of “if” which will not

*If a is true and b is not true

Ex. If plastic_cup unless glass_cup

31
Q

==

A

Id check and is method

Ex. If carrot == true
print “I love vegetables”
end

32
Q

«

A

Concatenation operator which means to append or add to the end

33
Q

gets

A

Kernel methods that will respond with a sting of what was typed

34
Q

[ ]

A

Index for a hash to find definition in a hash

35
Q

each

A

Method for arrays, hashes, and strings. It will go through each item

36
Q

gsub

A

Global substitution which will search and replace.

Ex. idea.gsub! (real, code )

37
Q

strip

A

Method that Removes all additional spaces and blank lines in a string

38
Q

File Class Methods

A

File::read( “file_name.txt” )

File::rename( “file_name.txt” , “file_name1.txt” )

File::delete( “file_name.txt” )

‘w’ = new file ‘r’ = read ‘a’ = add

39
Q

sort_by

A

A method that iterates or cycles through a list of things

Other methods are next and break

40
Q

Domination

A

Learning how to use the answers methods give back

41
Q

elseif

A

Used when u want to see if an object is true or false.

42
Q

next

A

Used to skip to the next item in a list

43
Q

break

A

Kicks you if an iterating loop

44
Q

def

A

Used to define methods

45
Q

Class

A

Used to define classes