本文共 567 字,大约阅读时间需要 1 分钟。
Ruby 中函数定义中参数使用 key=value 和 key:value 似乎是差不多的,但是其实还是有很大差异的,特别是有不止一个参数时:
[root@master ruby_learning]# cat test.rbdef test(host = HOST, port = PORT, index = 'jobs') puts [host, port, index].inspectenddef test2(host = HOST, port = PORT, index: 'jobs') puts [host, port, index].inspectendHOST='localhost'PORT='8200'test(index='nice')test(HOST, PORT, index='nice')putstest2(index:'nice')test2(HOST, PORT, index:'nice')[root@master ruby_learning]# ruby test.rb["nice", "8200", "jobs"]["localhost", "8200", "nice"]["localhost", "8200", "nice"]["localhost", "8200", "nice"]
转载地址:http://vnjqi.baihongyu.com/