Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
IPAddr#===
(untyped other) -> bool
===(other)
lib/ipaddr.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/ipaddr.rb, line 196
def include?(other)
other = coerce_other(other)
return false unless other.family == family
begin_addr <= other.begin_addr && end_addr >= other.end_addr
end
Alias of #include?
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