lib/better_ipaddr/classes.rb in better_ipaddr-0.1.2 vs lib/better_ipaddr/classes.rb in better_ipaddr-0.1.3
- old
+ new
@@ -10,11 +10,18 @@
def inherited(cls)
cls.extend BetterIpaddr::ClassMethods
end
def self.[](address, mask = nil, family: self::FAMILY)
- if mask
- new(address, family).mask(new(mask, family).to_s)
+ case mask
+ when Integer
+ if 0 <= mask && mask <= FAMILY_TO_BIT_LENGTH[family]
+ new(address, family).mask(mask)
+ else
+ new(address, family).mask(new(mask, family).to_s)
+ end
+ when String, IPAddr
+ new(address, family).mask(mask.to_s)
else
new(address, family)
end
end