Skip to content

Instantly share code, notes, and snippets.

@headius
Created August 18, 2016 19:45
Show Gist options
  • Save headius/1ea44e9854f814e9a23d52059aafc573 to your computer and use it in GitHub Desktop.
Save headius/1ea44e9854f814e9a23d52059aafc573 to your computer and use it in GitHub Desktop.
diff --git a/lib/ruby/stdlib/forwardable.rb b/lib/ruby/stdlib/forwardable.rb
index cd15eea..e20f5e3 100644
--- a/lib/ruby/stdlib/forwardable.rb
+++ b/lib/ruby/stdlib/forwardable.rb
@@ -178,6 +178,11 @@ module Forwardable
# q.push 23 #=> NoMethodError
#
def def_instance_delegator(accessor, method, ali = method)
+ accessor = accessor.to_s
+ if method_defined?(accessor) || private_method_defined?(accessor)
+ accessor = "#{accessor}()"
+ end
+
line_no = __LINE__; str = %{
def #{ali}(*args, &block)
begin
@@ -270,7 +275,12 @@ module SingleForwardable
# the method of the same name in _accessor_). If _new_name_ is
# provided, it is used as the name for the delegate method.
def def_single_delegator(accessor, method, ali = method)
- str = %{
+ accessor = accessor.to_s
+ if method_defined?(accessor) || private_method_defined?(accessor)
+ accessor = "#{accessor}()"
+ end
+
+ line_no = __LINE__; str = %{
def #{ali}(*args, &block)
begin
#{accessor}.__send__(:#{method}, *args, &block)
@@ -281,7 +291,7 @@ module SingleForwardable
end
}
- instance_eval(str, __FILE__, __LINE__)
+ instance_eval(str, __FILE__, line_no)
end
alias delegate single_delegate
diff --git a/lib/ruby/stdlib/irb.rb b/lib/ruby/stdlib/irb.rb
index 45f3280..92b79b3 100644
--- a/lib/ruby/stdlib/irb.rb
+++ b/lib/ruby/stdlib/irb.rb
@@ -525,7 +525,7 @@ module IRB
print messages.join("\n"), "\n"
unless lasts.empty?
printf "... %d levels...\n", levels if levels > 0
- print lasts.join("\n")
+ print lasts.join("\n"), "\n"
end
print "Maybe IRB bug!\n" if irb_bug
end
diff --git a/lib/ruby/stdlib/irb/ext/save-history.rb b/lib/ruby/stdlib/irb/ext/save-history.rb
index 236f00f..ab64cf5 100644
--- a/lib/ruby/stdlib/irb/ext/save-history.rb
+++ b/lib/ruby/stdlib/irb/ext/save-history.rb
@@ -27,6 +27,7 @@ module IRB
IRB.conf[:SAVE_HISTORY]
end
+ remove_method :save_history= if respond_to?(:save_history=)
# Sets <code>IRB.conf[:SAVE_HISTORY]</code> to the given +val+ and calls
# #init_save_history with this context.
#
diff --git a/lib/ruby/stdlib/logger.rb b/lib/ruby/stdlib/logger.rb
index 2246673..5a310ba 100644
--- a/lib/ruby/stdlib/logger.rb
+++ b/lib/ruby/stdlib/logger.rb
@@ -416,7 +416,7 @@ class Logger
# * Append open does not need to lock file.
# * If the OS supports multi I/O, records possibly may be mixed.
#
- def add(severity, message = nil, progname = nil, &block)
+ def add(severity, message = nil, progname = nil)
severity ||= UNKNOWN
if @logdev.nil? or severity < @level
return true
diff --git a/lib/ruby/stdlib/net/ftp.rb b/lib/ruby/stdlib/net/ftp.rb
index 26bca1a..cfd8cf7 100644
--- a/lib/ruby/stdlib/net/ftp.rb
+++ b/lib/ruby/stdlib/net/ftp.rb
@@ -1270,6 +1270,10 @@ module Net
def read_timeout=(sec)
end
+ def closed?
+ true
+ end
+
def close
end
diff --git a/lib/ruby/stdlib/ostruct.rb b/lib/ruby/stdlib/ostruct.rb
index 5aea046..17efcdc 100644
--- a/lib/ruby/stdlib/ostruct.rb
+++ b/lib/ruby/stdlib/ostruct.rb
@@ -71,6 +71,11 @@
# of these properties compared to using a Hash or a Struct.
#
class OpenStruct
+ # :nodoc:
+ class << self
+ alias allocate new
+ end
+
#
# Creates a new OpenStruct object. By default, the resulting OpenStruct
# object will have no attributes.
@@ -163,7 +168,7 @@ class OpenStruct
#
def new_ostruct_member(name)
name = name.to_sym
- unless respond_to?(name)
+ unless singleton_class.method_defined?(name)
define_singleton_method(name) { @table[name] }
define_singleton_method("#{name}=") { |x| modifiable[name] = x }
end
@@ -171,6 +176,11 @@ class OpenStruct
end
protected :new_ostruct_member
+ def freeze
+ @table.each_key {|key| new_ostruct_member(key)}
+ super
+ end
+
def respond_to_missing?(mid, include_private = false)
mname = mid.to_s.chomp("=").to_sym
@table.key?(mname) || super
diff --git a/lib/ruby/stdlib/resolv.rb b/lib/ruby/stdlib/resolv.rb
index eb158c6..22b8401 100644
--- a/lib/ruby/stdlib/resolv.rb
+++ b/lib/ruby/stdlib/resolv.rb
@@ -2455,14 +2455,14 @@ class Resolv
when IPv6
return arg
when String
- address = ''
+ address = ''.b
if Regex_8Hex =~ arg
arg.scan(/[0-9A-Fa-f]+/) {|hex| address << [hex.hex].pack('n')}
elsif Regex_CompressedHex =~ arg
prefix = $1
suffix = $2
- a1 = ''
- a2 = ''
+ a1 = ''.b
+ a2 = ''.b
prefix.scan(/[0-9A-Fa-f]+/) {|hex| a1 << [hex.hex].pack('n')}
suffix.scan(/[0-9A-Fa-f]+/) {|hex| a2 << [hex.hex].pack('n')}
omitlen = 16 - a1.length - a2.length
@@ -2478,8 +2478,8 @@ class Resolv
elsif Regex_CompressedHex4Dec =~ arg
prefix, suffix, a, b, c, d = $1, $2, $3.to_i, $4.to_i, $5.to_i, $6.to_i
if (0..255) === a && (0..255) === b && (0..255) === c && (0..255) === d
- a1 = ''
- a2 = ''
+ a1 = ''.b
+ a2 = ''.b
prefix.scan(/[0-9A-Fa-f]+/) {|hex| a1 << [hex.hex].pack('n')}
suffix.scan(/[0-9A-Fa-f]+/) {|hex| a2 << [hex.hex].pack('n')}
omitlen = 12 - a1.length - a2.length
diff --git a/lib/ruby/stdlib/uri/generic.rb b/lib/ruby/stdlib/uri/generic.rb
index c9e614f..aa793b2 100644
--- a/lib/ruby/stdlib/uri/generic.rb
+++ b/lib/ruby/stdlib/uri/generic.rb
@@ -1341,7 +1341,7 @@ module URI
# Constructs String from URI
#
def to_s
- str = String.new
+ str = ''.dup
if @scheme
str << @scheme
str << ':'
diff --git a/lib/ruby/stdlib/uri/http.rb b/lib/ruby/stdlib/uri/http.rb
index d43e9a2..81ae846 100644
--- a/lib/ruby/stdlib/uri/http.rb
+++ b/lib/ruby/stdlib/uri/http.rb
@@ -63,6 +63,7 @@ module URI
return super(tmp)
end
+=begin
#
# == Description
#
@@ -75,8 +76,8 @@ module URI
#
# Example:
#
- # uri = URI::HTTP.new('http', nil, "www.example.com", nil, "/path",
- # "query", 'fragment')
+ # uri = URI::HTTP.new("http", nil, "www.example.com", nil, nil,
+ # "/path", nil, "query", "fragment")
#
#
# See also URI::Generic.new
@@ -84,6 +85,7 @@ module URI
def initialize(*arg)
super(*arg)
end
+=end
#
# == Description
diff --git a/lib/ruby/stdlib/win32/registry.rb b/lib/ruby/stdlib/win32/registry.rb
index 4ff88ba..773e6fc 100644
--- a/lib/ruby/stdlib/win32/registry.rb
+++ b/lib/ruby/stdlib/win32/registry.rb
@@ -333,11 +333,11 @@ For detail, see the MSDN[http://msdn.microsoft.com/library/en-us/sysinfo/base/pr
end
def DeleteValue(hkey, name)
- check RegDeleteValue.call(hkey, make_wstr(name))
+ check RegDeleteValueW.call(hkey, make_wstr(name))
end
def DeleteKey(hkey, name)
- check RegDeleteKey.call(hkey, make_wstr(name))
+ check RegDeleteKeyW.call(hkey, make_wstr(name))
end
def FlushKey(hkey)
diff --git a/lib/ruby/stdlib/xmlrpc/client.rb b/lib/ruby/stdlib/xmlrpc/client.rb
index 3cb9e9a..587a80b 100644
--- a/lib/ruby/stdlib/xmlrpc/client.rb
+++ b/lib/ruby/stdlib/xmlrpc/client.rb
@@ -433,6 +433,24 @@ module XMLRPC # :nodoc:
Net::HTTP.new host, port, proxy_host, proxy_port
end
+ def dup_net_http
+ http = net_http(@http.address,
+ @http.port,
+ @http.proxy_address,
+ @http.proxy_port)
+ http.proxy_user = @http.proxy_user
+ http.proxy_pass = @http.proxy_pass
+ if @http.use_ssl?
+ http.use_ssl = true
+ Net::HTTP::SSL_ATTRIBUTES.each do |attribute|
+ http.__send__("#{attribute}=", @http.__send__(attribute))
+ end
+ end
+ http.read_timeout = @http.read_timeout
+ http.open_timeout = @http.open_timeout
+ http
+ end
+
def set_auth
if @user.nil?
@auth = nil
@@ -464,10 +482,7 @@ module XMLRPC # :nodoc:
if async
# use a new HTTP object for each call
- http = net_http(@host, @port, @proxy_host, @proxy_port)
- http.use_ssl = @use_ssl if @use_ssl
- http.read_timeout = @timeout
- http.open_timeout = @timeout
+ http = dup_net_http
# post request
http.start {
@@ -612,4 +627,3 @@ module XMLRPC # :nodoc:
end # class Client
end # module XMLRPC
-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment