diff options
| author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-04-24 06:08:32 +0000 |
|---|---|---|
| committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-04-24 06:08:32 +0000 |
| commit | 2cc6172caffdb67496aa777167612c8355b7a55e (patch) | |
| tree | d142293a3e11a7040976b226899b4ba537cbf201 /lib | |
| parent | 635a5e27ba912c6685820666a307ed1cd8926def (diff) | |
| download | ruby-2cc6172caffdb67496aa777167612c8355b7a55e.tar.gz ruby-2cc6172caffdb67496aa777167612c8355b7a55e.tar.xz ruby-2cc6172caffdb67496aa777167612c8355b7a55e.zip | |
* lib/ipaddr.rb (include?): Support non-IPAddr parameters by Dave Thomas. [ruby-core:00980]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3718 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ipaddr.rb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/ipaddr.rb b/lib/ipaddr.rb index 2a7419aa4..b8befe849 100644 --- a/lib/ipaddr.rb +++ b/lib/ipaddr.rb @@ -131,9 +131,13 @@ class IPAddr other_addr = other.to_i other_family = other.family end - if family != other_family - return false - end + else # Not IPAddr - assume integer in same family as us + other_addr = other.to_i + other_family = family + end + + if family != other_family + return false end return ((addr & mask_addr) == (other_addr & mask_addr)) end @@ -685,6 +689,12 @@ class TC_Operator < Test::Unit::TestCase assert_equal(true, net1.include?(IPAddr.new("192.168.2.0"))) assert_equal(true, net1.include?(IPAddr.new("192.168.2.255"))) assert_equal(false, net1.include?(IPAddr.new("192.168.3.0"))) + # test with integer parameter + int = (192 << 24) + (168 << 16) + (2 << 8) + 13 + + assert_equal(true, net1.include?(int)) + assert_equal(false, net1.include?(int+255)) + end end |
