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

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;

9 Cards in this Set

  • Front
  • Back

Consider the following method and a call to that method:




def my_method(a, b = 2, c = 3, d)


p [a, b, c, d]


end


my_method(4, 5, 6)




Use the ruby documentation to determine what this code will print.

[4, 5, 3, 6]


See here for explanation:


http://ruby-doc.org/core-2.3.2/doc/syntax/calling_methods_rdoc.html

Give an example of positional arguments for a method

my_method(argument1, argument2)

Give an example of default positional arguments for a method

def my_method(a, b, c = 3, d = 4)


p [a, b, c, d]


end


Here c and d have default values which ruby will apply for you. If you send only two arguments to this method:


my_method(1, 2)


You will see ruby print [1, 2, 3, 4].



What will this print?




def my_method(a, b, c = 3, d = 4)


p [a, b, c, d]


end




my_method(1, 2, 5)

[1, 2, 5, 4]




Ruby fills in the missing arguments from left to right.



What is the order that methods accept arguments?




Keyword


Block


Positional

Positional > Keyword > Block

Give an example of keyword arguments for a method

my_method(positional1, keyword1: value1, keyword2: value2)




Note that positional arguments are always accounted for first by the method.

Give an example of block arguments for a method

my_method do


# ...


end


OR ANOTHER WAY TO EXPRESS THIS


my_method {


# ...


}

Note do/end has lower precedence then {...}

What method could you use to right justify a str object?

rjust()


a = "hello"


a.rjust(20) #=> " hello"


This method is not destructive

Fill in the blank




  • Class methods are called on the_____



  • Instance methods are called on ______
  1. class
  2. objects