Last active
August 30, 2019 02:11
-
-
Save mrgenixus/354e5a704730282c52260b305f291f5d to your computer and use it in GitHub Desktop.
arguments in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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