Class: Ruby
- Inherits:
-
Object
- Object
- Ruby
- Defined in:
- lib/detectors/ruby.rb
Overview
Detects your current IP via Ruby Sockets
Instance Method Summary collapse
- #detect ⇒ Object
-
#initialize(version) ⇒ Ruby
constructor
A new instance of Ruby.
Constructor Details
#initialize(version) ⇒ Ruby
Returns a new instance of Ruby.
6 7 8 |
# File 'lib/detectors/ruby.rb', line 6 def initialize(version) @version = version == 6 ? 6 : 4 end |
Instance Method Details
#detect ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/detectors/ruby.rb', line 10 def detect ip_addresses = if @version == 6 Socket.ip_address_list.select(&:ipv6?).reject(&:ipv6_loopback?) else Socket.ip_address_list.select(&:ipv4?).reject(&:ipv4_loopback?) end ip = ip_addresses.first.ip_address raise 'no ip detected' unless ip ip end |