Blocks and sorting Flashcards
1
Q
define a method called greeting that prints “Hello world!”
A
def greeting
puts “Hello World!”
end
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!
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”)
4
Q
what does return do in methods?
A
it returns back the value evaluated using this method.
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
6
Q
define a method that takes 2 arguments and the 2nd is false by default
A
def my_method(arg1, arg2=false)