Object Types Flashcards
To find information on objects, classes, methods, etc… Where would you find these answers?
www.ruby-doc.org/core/
To find information on a method within Ruby, what command do you issue in Ruby to find more information?
ri object name
for example ri upcase
or
.inspect shows human readable form
True of False:
Variables are objects?
False
However, once a variable is defined, it will act like an object
What does this error code mean?
NameError: undefined local variable or method `x’ for main:Object
It means you have not defined your variable, in this case, the variable ‘x’
Variables should be named in what format?
lower case with underscores
for example: articles_written = 100
The scope indicator of the Global scope is what?
Dollar sign
example: $variable
The scope indicator of the Class scope is what?
Two at symbols
example: @@variable
The scope indicator of the Instance scope is what?
The at symbol
example: @variable
The scope indicator of the Local scope is what?
nothing, just the variable name
example: variable
The scope indicator of the Block scope is what?
nothing, just the variable name
example: variable
Ruby separates integers in two categories, what are they?
> integers
> floats
If integers are objects, what two subclasses must they belong to?
Fixnum and Bignum
examples:
1234. class => Fixnum
12345678. class => Bignum
What would the result be in Ruby?
-200.abs
=> 200
Since .abs returns the absolute value
What would the result be in Ruby?
200.next
=> 201
Since .next returns the next value
Floats or Floating point numbers are also known as what?
decimal numbers or precision numbers
x = 10 y = 10.0
what would x and y equal in Ruby?
10.0
10 / 3 in Ruby would return what value?
3
10.0 / 3.0 in Ruby would return what?
3.33333333333333
If you wanted to round this number, what would you enter in Ruby?
12345.6789
12345.6789.round
=> 12346
If you wanted to make this number an integer, what would you enter in Ruby?
12345.6789
12345.6789.to_i
=> 12345
If you wanted to round this number UP, what would you enter in Ruby?
12345.6789
12345.6789.floor
=> 12345
If you wanted to round this number DOWN, what would you enter in Ruby?
12345.6789
12345.6789.ceil
=> 12346