Object Types Flashcards

(56 cards)

1
Q

To find information on objects, classes, methods, etc… Where would you find these answers?

A

www.ruby-doc.org/core/

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

To find information on a method within Ruby, what command do you issue in Ruby to find more information?

A

ri object name
for example ri upcase
or
.inspect shows human readable form

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

True of False:

Variables are objects?

A

False

However, once a variable is defined, it will act like an object

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

What does this error code mean?

NameError: undefined local variable or method `x’ for main:Object

A

It means you have not defined your variable, in this case, the variable ‘x’

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

Variables should be named in what format?

A

lower case with underscores

for example: articles_written = 100

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

The scope indicator of the Global scope is what?

A

Dollar sign

example: $variable

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

The scope indicator of the Class scope is what?

A

Two at symbols

example: @@variable

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

The scope indicator of the Instance scope is what?

A

The at symbol

example: @variable

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

The scope indicator of the Local scope is what?

A

nothing, just the variable name

example: variable

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

The scope indicator of the Block scope is what?

A

nothing, just the variable name

example: variable

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

Ruby separates integers in two categories, what are they?

A

> integers

> floats

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

If integers are objects, what two subclasses must they belong to?

A

Fixnum and Bignum

examples:
1234. class => Fixnum
12345678. class => Bignum

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

What would the result be in Ruby?

-200.abs

A

=> 200

Since .abs returns the absolute value

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

What would the result be in Ruby?

200.next

A

=> 201

Since .next returns the next value

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

Floats or Floating point numbers are also known as what?

A

decimal numbers or precision numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
x = 10
y = 10.0

what would x and y equal in Ruby?

A

10.0

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

10 / 3 in Ruby would return what value?

A

3

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

10.0 / 3.0 in Ruby would return what?

A

3.33333333333333

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

If you wanted to round this number, what would you enter in Ruby?
12345.6789

A

12345.6789.round

=> 12346

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

If you wanted to make this number an integer, what would you enter in Ruby?
12345.6789

A

12345.6789.to_i

=> 12345

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

If you wanted to round this number UP, what would you enter in Ruby?
12345.6789

A

12345.6789.floor

=> 12345

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

If you wanted to round this number DOWN, what would you enter in Ruby?
12345.6789

A

12345.6789.ceil

=> 12346

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

strings are a sequence of what?

24
Q

what does this return in irb?

“Lamda”*3

A

“LamdaLamdaLamda”

25
Which character lets you escape a quote?
\ also known as a backslash
26
What does this yield? greeting = "hello" target = "world" puts "I want to say #{greeting} #{target}."
I want to say hello world.
27
What method makes a string backward?
.reverse example: "Hello".revers => "olleH"
28
What method makes a string capitalized?
.capitalize example: "hello".capitalize => "Hello"
29
What method makes a string all lower cased?
.downcase example: "Hello".downcase => "hello"
30
What method makes a string all upper cased?
.upcase example: "Hello".upcase => "HELLO"
31
If you wanted to count how many letters there were in the string "Hello", what would you enter?
"Hello".length => 5
32
Take "hello" and reverse it, make it all upper case, and count the letters
"Hello".reverse.upcase.length => 5
33
Define an array.
An ORDERED INTEGER-INDEXED collection of OBJECTS
34
Name 4 things that can go in an array
1. Strings 2. Numbers 3. Other arrays 4. Mixed Types
35
Enter what to make an empty array called master_array
master_array = []
36
put the letters a, b, and c in an array named my_first_letters
my_first_letters = ["a", "b", "c"]
37
given this array: my_first_letters = ["a", "b", "c"] what would this return: my_first_letters[1]
"b"
38
given this array: my_first_pets = ["dog", "pig", "cat"] what would you enter to turn "cat" into "goat"
my_first_pets[2] = "goat"
39
to clear out an array, what method would you use?
my_array.clear
40
if you wanted to append "goat" onto the array my_first_pets = ["dog", "pig", "cat"] what would you enter?
my_first_pets << "goat"
41
Given this array: my_first_pets = ["dog", "pig", "cat", "goat", "cat", "dog"] What would you enter to get an array containing only one type of animal (no duplicates)
my_first_pets.uniq
42
Given this array: my_first_pets = ["dog", "pig", "cat", "goat", "dog"] What would you enter to get an array containing only dogs and pigs?
my_first_pets.delete_at(2) => ["dog", "pig", "goat", "dog"]
43
Define hashes
UNORDERED collection of objects connected by KEY-VALUE PAIRS
44
Make a hash named my_hash
my_hash = {}
45
Make a hash named my_hash with the key value pairs of 'first item' and 'bong'
my_hash = {"first_item"=>"bong"}
46
Given this hash> name = {"first_name" => "Roberto", "last_name"=>"Sanchez"} how would you get the first name out?
name["first_name"]
47
Given this hash> name = {"first_name" => "Roberto", "last_name"=>"Sanchez"} What would this return? name.index("Sanchez")
=> "last_name"
48
create a symbol named after your test project
:test_project
49
create a hash with two symbols for first and last names
name = {:first_name => "Roberto", :last_name => "Sanchez"}
50
Define a boolean
something that is either True or False
51
What is the comparison & logic operator for 'equal'?
==
52
What is the comparison & logic operator for 'less than or equal to'?
<=
53
What is the comparison & logic operator for 'Not'?
!
54
What is the comparison & logic operator for 'Not equal'?
!=
55
What is the comparison & logic operator for 'and'?
&&
56
What is the comparison & logic operator for 'or'?
||