Skip to content

Instantly share code, notes, and snippets.

@drewdeponte
Created August 3, 2015 07:41
Show Gist options
  • Save drewdeponte/6e48bdbca04bbec576fb to your computer and use it in GitHub Desktop.
Save drewdeponte/6e48bdbca04bbec576fb to your computer and use it in GitHub Desktop.
test_default_value_params
#!/usr/bin/env ruby
def foo(a, b, c = 1, d = 2)
puts "a: #{a.inspect}"
puts "b: #{b.inspect}"
puts "c: #{c.inspect}"
puts "d: #{d.inspect}"
end
puts "Example 1: Two Arguments Passed"
puts
foo("hi", "there")
puts
puts "Example 2: Three Arguments Passed"
puts
foo("hi", "there", "bob")
puts
puts "Example 3: Four Arguments Passed"
puts
foo("hi", "there", "bob", "cindy")
#########################
#### Output of Run Below
#########################
#
# Example 1: Two Arguments Passed
#
# a: "hi"
# b: "there"
# c: 1
# d: 2
#
# Example 2: Three Arguments Passed
#
# a: "hi"
# b: "there"
# c: "bob"
# d: 2
#
# Example 3: Four Arguments Passed
#
# a: "hi"
# b: "there"
# c: "bob"
# d: "cindy"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment