diff options
| author | eahlstrom <erik@negahok.se> | 2010-12-16 23:37:36 +0100 |
|---|---|---|
| committer | eahlstrom <erik@negahok.se> | 2010-12-16 23:37:36 +0100 |
| commit | 4ba10f58a8642ad9d4e421d5c23da1d2e2fb8af1 (patch) | |
| tree | 56b4c196f718ab37d0540f7ff0887d3da57ed675 | |
| parent | 620f131f2f46cd56d08b13ec60c512006e59d352 (diff) | |
| download | ipaddress-4ba10f58a8642ad9d4e421d5c23da1d2e2fb8af1.tar.gz | |
Removed one level of nested if's.
| -rw-r--r-- | lib/ipaddress/ipv4.rb | 11 |
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 |
