• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/29

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

29 Cards in this Set

  • Front
  • Back

What is returned by the inspect method (Object#inspect)?

Object#inspect returns a debugging string that represents the Ruby object.




The default inspect shows the object's class name, an encoding of the object ID, and a list of the instance variables and their values (by calling inspect on each of them).




User defined classes should override this method to provide a better representation of obj.

What (if any) arguments does the inspect method (Object#inspect) take?

Object#inspect takes no arguments.

Does the inspect method (Object#inspect) have any useful side-effects?

No.

What is returned by the to_s method (Object#to_s)?

Object#to_s returns a string representing the object.




The default to_s prints the object's class and an encoding of the object id.




As a special case, the top-level object that is the initial execution context of Ruby programs returns "main".

What (if any) arguments does the to_s method (Object#to_s) take?

Object#to_s takes no arguments.

Does the to_s method (Object#to_s) have any useful side-effects?

No.

What is returned by the print method (Kernel#print)?

Kernel#print returns the nil object.

What (if any) arguments does the print method (Kernel#print) take?

Kernel#print can take:




No arguments - $_ printed, nil returned




One argument - Argument printed, argument returned




Multiple arguments - Each argument printed, an array containing all the arguments is returned.

Does the print method (Kernel#print) have any useful side-effects?

Kernel#print prints each object in turn to $stdout.




If the output field separator ($,) is not nil, its contents will appear between each field.




If the output record separator ($\) is not nil, it will be appended to the output.




If no arguments are given, prints $_.




Objects that aren't strings will be converted by calling their to_s method.

What is returned by the p method (Kernel#p)?

The return value of Kernel#p depends on how many parameters it received.




No Parameters -> the nil object




One Parameter -> the parameter itself




Many Paramters -> an array containing the parameters

What (if any) arguments does the p method (Kernel#p) take?

Kernel#p can take:




No arguments - nothing printed, nil returned




One argument - Argument.inspect printed, argument returned




Multiple arguments - Each argument.inspect printed, an array containing all the arguments is returned.

Does the p method (Kernel#p) have any useful side-effects?

Kernel#p directly writes obj.inspect followed by a newline for each parameter to the program’s standard output.

What is the difference between a local variable and an instance variable?

Local variables are confined to the scope in which they are declared (usually within a method). Local variables will not persist.

Instance variables are confined to the scope of the entire instance of an object and can be accessed from any of its methods. They persist for the lifetime of the object.

Which letter can be used as a modifier to create String literals with % notation in Ruby?

Q

What is the difference between using the lower-case (%q) and the upper-case (%Q) modifier when creating String literals with % notation in Ruby?

Lower-case (%q) doesn't interpolate (aside from escaping the backslash and any delimiter pairs that may appear in the literal).




Lower-case may be thought of as an analog for single-quotes and upper-case for double-quotes.

When using % notation to create a String literal, are line-breaks captured? Is indentation?

Yes.




%q{line one


line two


}
=> 'line one\n line two\n '

Which letter can be used as a modifier to create an Array literal using words separated by white space with % notation in Ruby?

W

What is the difference between using the lower-case (%w) and the upper-case (%W) modifier when creating word Array literals with % notation in Ruby?

Lower-case (%w) doesn't perform interpolation on the word elements (aside from escaping the backslash and any delimiter pairs that may appear in the literal).




Lower-case may be thought of as an analog for single-quotes and upper-case for double-quotes.

Kernel#require, #load, and #require_relative have differences, but ignoring those for the moment, what do these methods do?

Kernel#require, #load, and #require_relative allow the user to load code either from their own project or from third party libraries.

What is returned by the require method (Kernel#require)?

Kernel#require returns true if the file is successfully loaded, or false if the file had already been loaded.




If the file’s path cannot be determined a LoadError is raised.

What (if any) arguments does the require method (Kernel#require) take?

Kernel#require takes only one file name as an argument.

Does the require method (Kernel#require) have any useful side-effects?

Yes. Kernel#require loads the code in the file, making it as if the code had been typed in place of the call to require.




When the file is loaded, it is added to $LOADED_FEATURES ($"). Files already appearing in $" will not be loaded again.

Where does the require method (Kernel#require) search for the file its been asked to load?

If the filename does not resolve to an absolute path, it will be searched for in the directories listed in $LOAD_PATH ($:).




The current working directory is not included in your path by default.

How does the require method (Kernel#require) handle file extensions?

If the filename has the extension “.rb”, it is loaded as a source file; if the extension is “.so”, “.o”, or “.dll”, or the default shared library extension on the current platform, Ruby loads the shared library as a Ruby extension.




Otherwise, Ruby tries adding “.rb”, “.so”, and so on to the name until found.




If the file named cannot be found, a LoadError will be raised.

Which types of variables from loaded code are available in the requiring program?

Any constants or globals within the loaded source file will be available in the calling program’s global namespace.




However, local variables will not be propagated to the loading environment.

How is require_relative (Kernel#require_relative) different from require (Kernel#require)?

Kernel#require_relative tries to load the library named string relative to the requiring file’s path.




Kernel#require

What is returned by the require_relative method (Kernel#require_relative)?

Kernel#require_relative returns true if the file is successfully loaded, or false if the file had already been loaded.




If the file’s path cannot be determined a LoadError is raised.

What (if any) arguments does the require_relative method (Kernel#require_relative) take?

Kernel#require_relative takes only one string as an argument. This string should be a filepath.

What does the or-equals operator (||=) do?

The or-equals operator only performs assignment if the variable being assigned is falsey (nil).