习题 18 命名、变量、代码和函数
2017-09-27 本文已影响0人
南北东西总相随
习题 18 命名、变量、代码和函数
# ex18.rb
def print_two(*args)
arg1, arg2 = args
puts "arg1: #{arg1}, arg2: #{arg2}"
end
def print_two_again(arg1, arg2)
puts "arg1: #{arg1}, arg2: #{arg2}"
end
def print_one(arg1)
puts "arg1: #{arg1}"
end
def print_none()
puts "I got nothin'."
end
print_two("Zed", "Shaw")
print_two_again("Zed", "Shaw")
print_one("First!")
print_none()
结果:
$ ruby ex18.rb
arg1: Zed, arg2: Shaw
arg1: Zed, arg2: Shaw
arg1: First!
I got nothin'.