Skip to content

Instantly share code, notes, and snippets.

@mrgenixus
Last active August 30, 2019 02:11
Show Gist options
  • Save mrgenixus/354e5a704730282c52260b305f291f5d to your computer and use it in GitHub Desktop.
Save mrgenixus/354e5a704730282c52260b305f291f5d to your computer and use it in GitHub Desktop.
arguments in ruby
def func a, c, d
puts "a: " + a.to_s
puts "c: " + c.to_s
puts "d: " + d.to_s
end
def func2 *args
puts args.to_s
end
def func3 *args, **options
puts "args: " + args.to_s
puts "options: " + options.to_s
end
# e is the first ordinal argument
# args collects the remainder of the ordinal arguments
# c and d are defaulted named arguments
# options collects the remainder of the named arguments
def func4 e, *args, c: 4, d: nil, **options
puts "e: " + e.to_s
puts "c: " + c.to_s
puts "d: " + d.to_s
puts "args: " + args.to_s
puts "options: " + options.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment