Object Types Flashcards

You may prefer our related Brainscape-certified flashcards:
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?

A

characters

24
Q

what does this return in irb?

“Lamda”*3

A

“LamdaLamdaLamda”

25
Q

Which character lets you escape a quote?

A

\

also known as a backslash

26
Q

What does this yield?

greeting = “hello”
target = “world”
puts “I want to say #{greeting} #{target}.”

A

I want to say hello world.

27
Q

What method makes a string backward?

A

.reverse

example: “Hello”.revers
=> “olleH”

28
Q

What method makes a string capitalized?

A

.capitalize

example: “hello”.capitalize
=> “Hello”

29
Q

What method makes a string all lower cased?

A

.downcase

example: “Hello”.downcase
=> “hello”

30
Q

What method makes a string all upper cased?

A

.upcase

example: “Hello”.upcase
=> “HELLO”

31
Q

If you wanted to count how many letters there were in the string “Hello”, what would you enter?

A

“Hello”.length

=> 5

32
Q

Take “hello” and reverse it, make it all upper case, and count the letters

A

“Hello”.reverse.upcase.length

=> 5

33
Q

Define an array.

A

An ORDERED INTEGER-INDEXED collection of OBJECTS

34
Q

Name 4 things that can go in an array

A
  1. Strings
  2. Numbers
  3. Other arrays
  4. Mixed Types
35
Q

Enter what to make an empty array called master_array

A

master_array = []

36
Q

put the letters a, b, and c in an array named my_first_letters

A

my_first_letters = [“a”, “b”, “c”]

37
Q

given this array:
my_first_letters = [“a”, “b”, “c”]
what would this return:
my_first_letters[1]

A

“b”

38
Q

given this array:
my_first_pets = [“dog”, “pig”, “cat”]
what would you enter to turn “cat” into “goat”

A

my_first_pets[2] = “goat”

39
Q

to clear out an array, what method would you use?

A

my_array.clear

40
Q

if you wanted to append “goat” onto the array my_first_pets = [“dog”, “pig”, “cat”]
what would you enter?

A

my_first_pets &laquo_space;“goat”

41
Q

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)

A

my_first_pets.uniq

42
Q

Given this array:
my_first_pets = [“dog”, “pig”, “cat”, “goat”, “dog”]
What would you enter to get an array containing only dogs and pigs?

A

my_first_pets.delete_at(2)

=> [“dog”, “pig”, “goat”, “dog”]

43
Q

Define hashes

A

UNORDERED collection of objects connected by KEY-VALUE PAIRS

44
Q

Make a hash named my_hash

A

my_hash = {}

45
Q

Make a hash named my_hash with the key value pairs of ‘first item’ and ‘bong’

A

my_hash = {“first_item”=>”bong”}

46
Q

Given this hash>
name = {“first_name” => “Roberto”, “last_name”=>”Sanchez”}

how would you get the first name out?

A

name[“first_name”]

47
Q

Given this hash>
name = {“first_name” => “Roberto”, “last_name”=>”Sanchez”}

What would this return?
name.index(“Sanchez”)

A

=> “last_name”

48
Q

create a symbol named after your test project

A

:test_project

49
Q

create a hash with two symbols for first and last names

A

name = {:first_name => “Roberto”, :last_name => “Sanchez”}

50
Q

Define a boolean

A

something that is either True or False

51
Q

What is the comparison & logic operator for ‘equal’?

A

==

52
Q

What is the comparison & logic operator for ‘less than or equal to’?

A

<=

53
Q

What is the comparison & logic operator for ‘Not’?

A

!

54
Q

What is the comparison & logic operator for ‘Not equal’?

A

!=

55
Q

What is the comparison & logic operator for ‘and’?

A

&&

56
Q

What is the comparison & logic operator for ‘or’?

A

||