mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/ipaddr.rb (include?): Support non-IPAddr parameters by Dave Thomas. [ruby-core:00980]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3718 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1de4203c51
commit
8e19c02e8f
2 changed files with 18 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Wed Apr 23 14:05:40 2003 Dave Thomas <dave@pragprog.com>
|
||||||
|
|
||||||
|
* lib/ipaddr.rb (include?): Support non-IPAddr parameters.
|
||||||
|
[ruby-core:00980]
|
||||||
|
|
||||||
Wed Apr 23 13:31:10 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Wed Apr 23 13:31:10 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* lib/cgi.rb (CGI::QueryExtension::[]): always return Value
|
* lib/cgi.rb (CGI::QueryExtension::[]): always return Value
|
||||||
|
|
|
@ -131,9 +131,13 @@ class IPAddr
|
||||||
other_addr = other.to_i
|
other_addr = other.to_i
|
||||||
other_family = other.family
|
other_family = other.family
|
||||||
end
|
end
|
||||||
if family != other_family
|
else # Not IPAddr - assume integer in same family as us
|
||||||
return false
|
other_addr = other.to_i
|
||||||
end
|
other_family = family
|
||||||
|
end
|
||||||
|
|
||||||
|
if family != other_family
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
return ((addr & mask_addr) == (other_addr & mask_addr))
|
return ((addr & mask_addr) == (other_addr & mask_addr))
|
||||||
end
|
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.0")))
|
||||||
assert_equal(true, net1.include?(IPAddr.new("192.168.2.255")))
|
assert_equal(true, net1.include?(IPAddr.new("192.168.2.255")))
|
||||||
assert_equal(false, net1.include?(IPAddr.new("192.168.3.0")))
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue