default arguments

When call a method with blank value in default arguments/with no argument in the position of default argument, the method uses the default value automatically….This is like “overload” in C++

What’s the idiom in Ruby when you want to have a default argument to a function, but one that is dependent on another parameter / another variable? another parameter / another variable?

def foo(a, l = a.size) end

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s