Tutorial by Examples

Suppose you had an array: pair = ['Jack','Jill'] And a method that takes two arguments: def print_pair (a, b) puts "#{a} and #{b} are a good couple!" end You might think you could just pass the array: print_pair(pair) # wrong number of arguments (1 for 2) (ArgumentError) Si...
The splat operator removes individual elements of an array and makes them into a list. This is most commonly used to create a method that accepts a variable number of arguments: # First parameter is the subject and the following parameters are their spouses def print_spouses(person, *spouses) s...

Page 1 of 1