summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreahlstrom <erik@negahok.se>2010-12-16 23:37:36 +0100
committereahlstrom <erik@negahok.se>2010-12-16 23:37:36 +0100
commit4ba10f58a8642ad9d4e421d5c23da1d2e2fb8af1 (patch)
tree56b4c196f718ab37d0540f7ff0887d3da57ed675
parent620f131f2f46cd56d08b13ec60c512006e59d352 (diff)
downloadipaddress-4ba10f58a8642ad9d4e421d5c23da1d2e2fb8af1.tar.gz
Removed one level of nested if's.
-rw-r--r--lib/ipaddress/ipv4.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/ipaddress/ipv4.rb b/lib/ipaddress/ipv4.rb
index 490f7a8..1ade6f2 100644
--- a/lib/ipaddress/ipv4.rb
+++ b/lib/ipaddress/ipv4.rb
@@ -538,6 +538,13 @@ module IPAddress;
end
#
+ # Checks that all other IPAddress::IPv4 is included in this object
+ #
+ def include_all?(*others)
+ others.find_all{|oth| include?(oth)}.length == others.length
+ end
+
+ #
# Checks if an IPv4 address objects belongs
# to a private network RFC1918
#
@@ -947,8 +954,8 @@ module IPAddress;
return [ip1]
else
snet = ip1.supernet(ip1.prefix-1)
- if snet.include?(ip1) && snet.include?(ip2)
- return ((ip1.size + ip2.size) == snet.size) ? [snet] : [ip1, ip2]
+ if snet.include_all?(ip1, ip2) && ((ip1.size + ip2.size) == snet.size)
+ return [snet]
else
return [ip1, ip2]
end