Optional parameter in functions

how do i make a parameter optional. if it is possible.
for eg. i want to do as follows

function myCall(a,b,c=somedefault)

end

myCall(a,b,c) or myCall(a,b)

Junkone wrote:

how do i make a parameter optional. if it is possible.
for eg. i want to do as follows

function myCall(a,b,c=somedefault)

end
myCall(a,b,c) or myCall(a,b)

Except for the fact that in ruby you define methods with “def” and
not “function”, what you wrote above is perfectly valid ruby code
and works as intended.

HTH,
Sebastian

2008/7/25 Junkone [email protected]:

how do i make a parameter optional. if it is possible.
for eg. i want to do as follows

function myCall(a,b,c=somedefault)

end

myCall(a,b,c) or myCall(a,b)

You’ve got the basic idea. You just set the optional parameter to a
default value

def hello( who = “World” )
puts “Hello, #{who}”
end
=> nil
hello “Bob”
Hello, Bob
=> nil
hello
Hello, World
=> nil

Farrel