G
grom
Is it possbile for Ruby to have keyword arguments added in like in
Python.
Quote from Python documentation:
4.7.2 Keyword Arguments
Functions can also be called using keyword arguments of the form
"keyword = value". For instance, the following function:
def parrot(voltage, state='a stiff', action='voom', type='Norwegian
Blue'):
print "-- This parrot wouldn't", action,
print "if you put", voltage, "Volts through it."
print "-- Lovely plumage, the", type
print "-- It's", state, "!"
could be called in any of the following ways:
parrot(1000)
parrot(action = 'VOOOOOM', voltage = 1000000)
parrot('a thousand', state = 'pushing up the daisies')
parrot('a million', 'bereft of life', 'jump')
but the following calls would all be invalid:
parrot() # required argument missing
parrot(voltage=5.0, 'dead') # non-keyword argument following keyword
parrot(110, voltage=220) # duplicate value for argument
parrot(actor='John Cleese') # unknown keyword
Python.
Quote from Python documentation:
4.7.2 Keyword Arguments
Functions can also be called using keyword arguments of the form
"keyword = value". For instance, the following function:
def parrot(voltage, state='a stiff', action='voom', type='Norwegian
Blue'):
print "-- This parrot wouldn't", action,
print "if you put", voltage, "Volts through it."
print "-- Lovely plumage, the", type
print "-- It's", state, "!"
could be called in any of the following ways:
parrot(1000)
parrot(action = 'VOOOOOM', voltage = 1000000)
parrot('a thousand', state = 'pushing up the daisies')
parrot('a million', 'bereft of life', 'jump')
but the following calls would all be invalid:
parrot() # required argument missing
parrot(voltage=5.0, 'dead') # non-keyword argument following keyword
parrot(110, voltage=220) # duplicate value for argument
parrot(actor='John Cleese') # unknown keyword