ruby – 如何记录提供块的方法是可选的?
发布时间:2020-12-17 03:17:17 所属栏目:百科 来源:网络整理
导读:我有一个记录如下的函数: ### Searches for street names in the local address database. Returns a list# of strings,or invokes the block for each result.## @param [String,Hash] query## Can be:## - A search string with optinal wildcards. Examp
我有一个记录如下的函数:
## # Searches for street names in the local address database. Returns a list # of strings,or invokes the block for each result. # # @param [String,Hash] query # # Can be: # # - A search string with optinal wildcards. Examples: # - "B?rumsv*" # - "Fornebuve_en" # # @param [Integer] limit # # Limits the amount of results. See {#search_street_addresses} for usage # examples. # # @return [Array<String>] # # A sorted array of street names. # # @yield [street_name] Invokes the block with a street name for each # result. # 产生这个结果: 我的问题是文档说该函数需要一个块并且它返回一个值.实际上,该块是可选的.如果提供了块,则为每个结果调用它,函数不返回任何内容(nil).如果未提供块,则结果将在Array中返回. 我如何在文档中明确说明?有推荐的方法吗? 解决方法
使用@overload
## # Searches for street names in the local address database. Returns a list # of strings,or invokes the block for each result. #@overload search_street_names(query,limit: nil) # @param [String,Hash] query # # Can be: # # - A search string with optinal wildcards. Examples: # - "B?rumsv*" # - "Fornebuve_en" # # @param [Integer] limit # # Limits the amount of results. See {#search_street_addresses} for usage # examples. # # @return [Array<String>] # # A sorted array of street names. # #@overload search_street_names(query,Hash] query # # Can be: # # - A search string with optinal wildcards. Examples: # - "B?rumsv*" # - "Fornebuve_en" # # @param [Integer] limit # # Limits the amount of results. See {#search_street_addresses} for usage # examples. # # @yield [street_name] Invokes the block with a street name for each # result. ## 返回: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |