Skip to content

Latest commit

 

History

History
29 lines (23 loc) · 879 Bytes

File metadata and controls

29 lines (23 loc) · 879 Bytes
lang EN
title Give and take
answer \d+
ok Right on. Bravo.
error

Most methods do not only want some parameters as input, but will also give something back. I have changed our method a bit so it will return a value to you. Try it:

def tame( number_of_shrews )
  number_of_shrews.times {
    puts "Tamed a shrew"
  }
  return number_of_shrews
end

puts tame(3)

Return

And, since you're getting so advanced and capable here, one other tip: you can omit the word return from the last line of the method. Ruby will automagically return the last value that was used inside the method.

So we can change the last line to just: number_of_shrews.

But since method .times also returns the number_of_shrews we can remove the entire last line. So in fact our original method already did what we wanted all along!