Blocks and sorting Flashcards

1
Q

define a method called greeting that prints “Hello world!”

A

def greeting
puts “Hello World!”
end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

define a method that takes your name as an argument, then call the function

A
def my_name(name)
  puts "Hey, #{name}!"
end

my_name(“Mina”)
» Hey, Mina!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

define a splat greeting method that does not know how many arguments will be

A
def what_up(greeting, *bros)
  bros.each { |bro| puts "#{greeting}, #{bro}!" }
end

what_up(“What up”, “Justin”, “Ben”, “Kevin Sorbo”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what does return do in methods?

A

it returns back the value evaluated using this method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

define a method that check if the number is divisible by 3

A
def by_three?(n)
  return n % 3 == 0
end

by_three?(9)
» true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

define a method that takes 2 arguments and the 2nd is false by default

A

def my_method(arg1, arg2=false)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly