The Ruby Programming Language

Calling Methods

#There is a lot of flexibility!

def my_method(a,b,c)
  puts a + " " + b + " " + c
end

my_method( 'j', 'o', 'e') # j o e

#default args

def get_data(name="peter")
  "#{name}"
end

get_data         #peter
get_data("john") #john

#Variable number of arguments
def varargs(first, *rest)
  "Got #{first} and #{rest.join(', ')}"
end

varargs("one") #Got one and 
varargs("one", "two", "three")#Got one and two, three
varargs "one", "two", "three" #Got one and two, three


José M. Vidal .

7 of 11