Me? Instead of homebrew, I'd cheat, and use ipaddr: 

#!/usr/bin/ruby 

require 'ipaddr' 

["3ffe:505:2::1", "3fge:505:2::1"].each do |ip|
 begin
 if(ipv6 = IPAddr.new ip)
 puts "#{ip} is a valid IPv6 address."
 end
 rescue IPAddr::InvalidAddressError
 puts "#{ip} is an invalid IPv6 address."
 end 
end 

On 2016-11-23 10:46, leam hall wrote: 

> Any good ways of improving this as an ipv6 validator? Calling scripts assume it's valid unless nil. 
> 
> Leam 
> 
> #### 
> 
> def self.ipv6(ip)
> return nil if ip.match(/:::/) 
> ip_array = ip.split(":")
> return nil if ip_array.count > 8 or ip_array.count < 1 
> ip_array.each do |octet|
> return nil if octet.length > 4
> return nil if octet.match(/[^[:xdigit:]]/)
> end 
> return ip
> end 
> 
> ####
> 
> -- 
> 
> Mind on a Mission [1] 
> 
> Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk [2]>

 

Links:
------
[1] http://leamhall.blogspot.com/
[2] http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk
(supressed text/html)
Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>