define methods that have arguments : Method Creation « Method « Ruby






define methods that have arguments


def repeat( word, times )
 puts word * times
end

repeat("Hello! ", 3) # => Hello! Hello! Hello!
repeat "Good-bye! ", 4 # => Good-bye! Good-bye! Good-bye! Good-bye!

 








Related examples in the same category

1.Creating and Calling a Method
2.A simple definition for a method named hello, created with the keywords def and end
3.You can a function with or without parenthesis
4.Call a function for a parameter with or without parenthesis
5.You can call another function based on the return from this funtion call
6.method with ?
7.Define a method to convert Cartesian (x,y) coordinates to Polar
8.Add a new method by add method to Class