Method: IPAccess::List#grep
- Defined in:
- lib/ipaccess/ip_access_list.rb
#grep(*addresses) ⇒ Object Also known as: search
This method finds all matching addresses in the list and returns an array containing these addresses. If the optional block is supplied, each matching element is passed to it, and the block‘s result is stored in the output array.
Ba aware that it may call the block for same object twice if you’ll pass two matching addresses.
See IPAccess.to_cidrs description for more info about arguments you may pass to it.
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ipaccess/ip_access_list.rb', line 136 def grep(*addresses) return [] if empty? out_ary = [] addrs = IPAccess.to_cidrs(*addresses) addrs.each do |addr| m = included_cidr(addr) out_ary.push( block_given? ? yield(m) : m) unless m.nil? end return out_ary end |