instance method
IPAddr#include?
(untyped other) -> bool
include?(other)
lib/ipaddr.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/ipaddr.rb, line 192
def include?(other)
other = coerce_other(other)
return false unless other.family == family
begin_addr <= other.begin_addr && end_addr >= other.end_addr
end
Returns true if the given ipaddr is in the range.
e.g.:
Example
require 'ipaddr' net1 = IPAddr.new("192.168.2.0/24") net2 = IPAddr.new("192.168.2.100") net3 = IPAddr.new("192.168.3.0") net4 = IPAddr.new("192.168.2.0/16") p net1.include?(net2) #=> true p net1.include?(net3) #=> false p net1.include?(net4) #=> false p net4.include?(net1) #=> true