Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

IPAddr#===

===(other)

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
See also #include? #== #>> #<=> also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0