1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

fix Forwardable warnings in WrappedModule/Candidate

This commit is contained in:
robert 2017-06-03 11:53:14 +01:00
parent 569f81f42e
commit f35957d42f
6 changed files with 32 additions and 14 deletions

View file

@ -2,12 +2,11 @@
# MIT License
#
require 'pp'
require 'pry/forwardable'
require 'pry/input_lock'
require 'pry/exceptions'
require 'pry/helpers/base_helpers'
require 'pry/hooks'
require 'forwardable'
class Pry
# The default hooks - display messages when beginning and ending Pry sessions.

23
lib/pry/forwardable.rb Normal file
View file

@ -0,0 +1,23 @@
class Pry
module Forwardable
require 'forwardable'
include ::Forwardable
#
# Since Ruby 2.4, Forwardable will print a warning when
# calling a method that is private on a delegate, and
# in the future it could be an error: https://bugs.ruby-lang.org/issues/12782#note-3
#
# That's why we revert to a custom implementation for delegating one
# private method to another.
#
def def_private_delegators(target, *private_delegates)
private_delegates.each do |private_delegate|
define_method(private_delegate) do |*a, &b|
instance_variable_get(target).__send__(private_delegate, *a, &b)
end
end
class_eval { private *private_delegates }
end
end
end

View file

@ -5,7 +5,7 @@ class Pry
LOCAL_RC_FILE = "./.pryrc"
class << self
extend Forwardable
extend Pry::Forwardable
attr_accessor :custom_completions
attr_accessor :current_line
attr_accessor :line_buffer

View file

@ -2,7 +2,7 @@ require 'forwardable'
class Pry
class REPL
extend Forwardable
extend Pry::Forwardable
def_delegators :@pry, :input, :output
# @return [Pry] The instance of {Pry} that the user is controlling.

View file

@ -102,7 +102,7 @@ def pry_eval(*eval_strs)
end
class PryTester
extend Forwardable
extend Pry::Forwardable
attr_reader :pry, :out

View file

@ -1,5 +1,4 @@
require 'pry/helpers/documentation_helpers'
require 'forwardable'
class Pry
class WrappedModule
@ -10,7 +9,7 @@ class Pry
class Candidate
include Pry::Helpers::DocumentationHelpers
include Pry::CodeObject::Helpers
extend Forwardable
extend Pry::Forwardable
# @return [String] The file where the module definition is located.
attr_reader :file
@ -22,15 +21,12 @@ class Pry
# Methods to delegate to associated `Pry::WrappedModule
# instance`.
private_delegates = [:lines_for_file, :method_candidates,
:yard_docs?]
public_delegates = [:wrapped, :module?, :class?, :name, :nonblank_name,
private_delegates = [:lines_for_file, :method_candidates, :yard_docs?, :name]
public_delegates = [:wrapped, :module?, :class?, :nonblank_name,
:number_of_candidates]
def_delegators :@wrapper, *(private_delegates + public_delegates)
private(*private_delegates)
public(*public_delegates)
def_delegators :@wrapper, *public_delegates
def_private_delegators :@wrapper, *private_delegates
# @raise [Pry::CommandError] If `rank` is out of bounds.
# @param [Pry::WrappedModule] wrapper The associated