Skip to content

Instantly share code, notes, and snippets.

@xiangzhuyuan
Last active January 14, 2022 01:38
Show Gist options
  • Save xiangzhuyuan/f86e754d25b389dd29a5437135f47ccc to your computer and use it in GitHub Desktop.
Save xiangzhuyuan/f86e754d25b389dd29a5437135f47ccc to your computer and use it in GitHub Desktop.
ruby method parameter
#https://docs.ruby-lang.org/ja/latest/class/Method.html#I_PARAMETERS
#ruby 的方法参数定义还是挺绕的, 足够灵活,足够困扰...
#从定义到使用, 似乎在两边会出现一些`意想不到`的事情.
#就是在定义这个方法的时候可能想是这样的, 结果后来在使用的时候却又忘记了初衷.
def a_method(a, b = 1, c = 2, d = 3, *aa, cli: true)
puts "......................."
puts "a #{a} |"
puts "b #{b} |"
puts "c #{c} |"
puts "d #{d} |"
puts "aa #{aa} |"
puts "cli #{cli} |"
puts "......................."
puts
puts
puts
end
a_method(1, 2, 3, 4, 5, 6, 7, 8, true, cli: false)
a_method(1)
a_method(1, cli: false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment