• 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/67

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;

67 Cards in this Set

  • Front
  • Back

.strip

function for String class to get rid of leading and trailing whitespace

.split

Divides an array into substrings based on a delimiter (commas, spaces)

someArray(&:someMethod)

calls to_proc to turn into:


something {|i| i.foo }


from


something(&:foo)

difference between a module and a class?

Modules are about creating functions and sharing them among multiple classes. Classes are about objects, modules are about methods.

What is '==' in Ruby?

Tests whether two things are equal in value. Tests equivalence



What is equal?() in Ruby?

Tests whether two objects are the same

Difference between 'and' and '&&' in Ruby?

'and' has a lower precedence than '='


'&&' has a higher precedence than '='

What is the basic syntax for giving a variable 'x' a regular expression output?



x = /someRegex/.match("some string")

Ruby string interpolation, how can you use it and what does it look like?



String interpolation is used with double quotes "", so for any number i, the syntax goes "#{i}"

What is the name of any constructor in Ruby code?

class someClass


initialize(someParameter)




end


end

Difference between super and super() in Ruby?

super calls the parent class with the same parameters pass in the child class, while super() calls the parent class with no parameters

obj1.eql?(obj2)

Checks whether the value and type of two operands are the same

"someString".gsub(/pattern/, "x")

returns a copy of the string where all occurrences of the pattern are replaced with 'x'

Explain %() in ruby

Creates a string within the parentheses

::

A way to access things in a class that are available at the class-level

+= vs. .concat()

+= reinitializes an object in ruby while .concat() merely concatenates what's in the parenthesis to the original object

someObject.respond_to?("someMethod")

checks whether or not an object has a specific method in it, including all the methods inherited by anscestors

.include?() .includes()

.include?() Ruby seems to take precedence in question marks...



difference between .each(), .collect(), .map()?

.each() returns the same array, while .collect() and .map() return new arrays

.push() in ruby?

Used for arrays

Difference between:


class Dog1


def bark() { return "woof woof" }


end


and


class Dog2


def self.bark() { return "woof woof" }


end

You'll have to instantiate an object in order to call on the first bark, while the second bark can be obtained at the class level:


fido = Dog1.new


puts fido.bark()


puts Dog2.bark()

What does this do?


.any? do end

it iterates over an array and will return true if the code block is ever true

What does this do?


.select() do end

iterates over an array and will return all the elements for which the code block is true

What does this do?


.find() do end

returns the first element in an array for which the code block returns true

What does this do?


.find_index() do end

returns the first index of an array for which the code block returns true

.to_f

turns an integer into a floating point number

how do you inherit a module into a class?

you put include somewhere in the class block

.merge()

merges two hashes together

What is the access control of of protected methods in ruby?

Protected methods can only be invoked by objects of the defining class and its subclasses.

How do you turn any object into a constant in ruby?

Object.freeze

What does .allocate() do?

If you have a class that has an initialize() function and you want to create an object but don't want to call its initialize

regular expression modifier: i

ignore case when matching text



regular expression modifier: o

perform #{} interpolation only once, the first time the regexp literal is evaluated

regular expression modifier: x

Ignores whitespace and allows comments in regular expressions

regex modifier: m

Matches multiple lines, recognizing newlines as normal characters

u,e,s,n

Interpret the regexp as Unicode (UTF-8), EUC, SJIS, or ASCII. If none of these modifiers is specified, the regular expression is assumed to use the source encoding.

How do you get the index for each character in a string in ruby?

each_char.with_index()

DID YOU KNOW you can do string interpolation into regex?

it looks like this. /#{someVariable}/

As a safe bet, which variable number should index be for each_index() operators?

the second one

how do you remove a value from an array directly in ruby?

someArray.delete(value)

How do get the n min/max values from an array?

someArray.min(n)

Describe the four ways in which the reduce function in ruby can be used.

reduce(initial, sym) → obj


reduce(sym) → obj


reduce(initial) { |memo, obj| block } → obj


reduce { |memo, obj| block } → obj

What is the exact same as .reduce() in ruby?

.inject()

what is the return value of .inject() in ruby?

the final value of memo

What happens when you put a binary operation in .reduce()? (example: .reduce(:+))

combines each of the values in array using the given binary operation

describe the syntax for ruby's case operation

case x


when (condition) ....


when(condition2).....


end

explain the ruby function:


someString.tr(from_str, to_str)

changes the characters in someString from the characters in from_string to to_string character by character

What are the different ways to call Ruby methods?

1.) Calling them directly using the dot operator


2.) Using the .send(:methodSym, params) method


3.) Instantiating the method object then using the .call() method. For example,


method_object = someObj.method(:someMethod)


method_object.call(optParams)


4.) Using the eval method:


eval "s.length"

How can you call private methods in Ruby?

class Flass


private


def hi


puts "hello world"


end


end


f = Flass.new


f.send :hi ## returns "hello world"


f.method(:hi).call ## returns "hello world"

array1 - array2 = ?

deletes item by item whatever's in array2 that is also in array1

.delete_at()

deletes the array item at that index

.match() vs =~

both return nil of there's no match


.match() returns matchData instance if there is a match and the other returns the numerical position where the match started

someMatch.string, what does this return?

it returns the original string matched

someMatch.regexp, what does this return?

it returns the regular expression used in the match



someMatch[0], what does this return?

the match between the string and the regexp for some .match() function

someMatch[n], what signified the number of n in someMatch?

the number of groupings used in the regular expression

for regular expressions, what is the difference between .sub() and .gsub()?

.sub() only changes the first match while .gsub() [think, global sub] changes all matches

What is the backslash-number pattern in ruby regular expressions? (\someNumber)

it is a variable holding one regular expression grouping

What is $1...$n in terms of ruby regular expressoins?

They are the global variables created denoting the grouping found for a regular expression match

What is the purpose of the '!!' (double bang) sign in ruby?

it is used for variables and transforms the variable to give its original boolean value in a boolean context. The first bang sign switches to variable to a boolean context, negates it, and the second bang sign negates that negation, resulting in the original boolean value for that variable in a boolean context

What is the difference between 'require' and 'require_relative' in Ruby?

With 'require', Ruby looks in the $LOAD_PATH global variable and checks if the file to require is there, while in 'require_relative', Ruby checks for the files relative to the file that you're in/requiring from.

What is the difference between 'be_kind_of' and 'be_instance_of' in Ruby?





be_instance_of returns true/false if the actual value is an instance of an expected class


be_kind_of returns true/false if the actual value is an instance of an expected class OR any of the class' parent classes

What is double() in Rspec?

Creates a mock of a dependency. it is the ruby version of mocking.

how is stubbing done in rspec?

through the allow() method with the syntax: allow(someClass).to receive(:someStub) { someValue }



.uniq in ruby?

removes all duplicates of items in an array

How do you run specific tests in rspec from the command line?

test_file.rb


it "do stuff", :customTag => true do


puts "runs when called"


end




command line:


rspec --tag customTag

how does one get very descriptive, formatted rspec test results?

rspec --format doc all_doc_names.rb