summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2025-11-09 21:30:03 +0900
committergit <svn-admin@ruby-lang.org>2025-11-09 12:45:48 +0000
commitd79ff407825352953293ea7c399cd3a94aef021f (patch)
tree7dc86b3952966077ef85f36f0886fa5f2aded038
parent063aea8ce47162e8cf0abc48e00bdbbc5dfcbea2 (diff)
[ruby/resolv] Require win32/resolv just once
And Use Win32::Resolv instead of a constant `WINDOWS`. https://github.com/ruby/resolv/commit/b2c775cd80
-rw-r--r--lib/resolv.rb12
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/resolv.rb b/lib/resolv.rb
index fce5092d0e..b7ed1dcb7a 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -174,21 +174,18 @@ class Resolv
class ResolvTimeout < Timeout::Error; end
- WINDOWS = /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM || ::RbConfig::CONFIG['host_os'] =~ /mswin/
- private_constant :WINDOWS
-
##
# Resolv::Hosts is a hostname resolver that uses the system hosts file.
class Hosts
- if WINDOWS
+ if /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM || ::RbConfig::CONFIG['host_os'] =~ /mswin/
begin
require 'win32/resolv' unless defined?(Win32::Resolv)
- DefaultFileName = Win32::Resolv.get_hosts_path || IO::NULL
+ hosts = Win32::Resolv.get_hosts_path || IO::NULL
rescue LoadError
end
end
- DefaultFileName ||= '/etc/hosts'
+ DefaultFileName = hosts || '/etc/hosts'
##
# Creates a new Resolv::Hosts, using +filename+ for its data source.
@@ -1022,8 +1019,7 @@ class Resolv
def Config.default_config_hash(filename="/etc/resolv.conf")
if File.exist? filename
Config.parse_resolv_conf(filename)
- elsif WINDOWS
- require 'win32/resolv' unless defined?(Win32::Resolv)
+ elsif defined?(Win32::Resolv)
search, nameserver = Win32::Resolv.get_resolv_info
config_hash = {}
config_hash[:nameserver] = nameserver if nameserver