Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions lib/delegate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
# Be advised, RDoc will not detect delegated methods.
#
class Delegator < BasicObject
# The version string
VERSION = "0.4.0"

kernel = ::Kernel.dup
Expand Down Expand Up @@ -77,7 +78,7 @@ def initialize(obj)
end

#
# Handles the magic of delegation through \_\_getobj\_\_.
# Handles the magic of delegation through +__getobj__+.
#
ruby2_keywords def method_missing(m, *args, &block)
r = true
Expand All @@ -94,7 +95,7 @@ def initialize(obj)

#
# Checks for a method provided by this the delegate object by forwarding the
# call through \_\_getobj\_\_.
# call through +__getobj__+.
#
def respond_to_missing?(m, include_private)
r = true
Expand All @@ -107,7 +108,7 @@ def respond_to_missing?(m, include_private)
r
end

KERNEL_RESPOND_TO = ::Kernel.instance_method(:respond_to?)
KERNEL_RESPOND_TO = ::Kernel.instance_method(:respond_to?) # :nodoc:
private_constant :KERNEL_RESPOND_TO

# Handle BasicObject instances
Expand All @@ -126,23 +127,23 @@ def respond_to_missing?(m, include_private)

#
# Returns the methods available to this delegate object as the union
# of this object's and \_\_getobj\_\_ methods.
# of this object's and +__getobj__+ methods.
#
def methods(all=true)
__getobj__.methods(all) | super
end

#
# Returns the methods available to this delegate object as the union
# of this object's and \_\_getobj\_\_ public methods.
# of this object's and +__getobj__+ public methods.
#
def public_methods(all=true)
__getobj__.public_methods(all) | super
end

#
# Returns the methods available to this delegate object as the union
# of this object's and \_\_getobj\_\_ protected methods.
# of this object's and +__getobj__+ protected methods.
#
def protected_methods(all=true)
__getobj__.protected_methods(all) | super
Expand Down Expand Up @@ -175,7 +176,7 @@ def eql?(obj)
end

#
# Delegates ! to the \_\_getobj\_\_
# Delegates ! to the +__getobj__+
#
def !
!__getobj__
Expand All @@ -198,7 +199,7 @@ def __setobj__(obj)
end

#
# Serialization support for the object returned by \_\_getobj\_\_.
# Serialization support for the object returned by +__getobj__+.
#
def marshal_dump
ivars = instance_variables.reject {|var| /\A@delegate_/ =~ var}
Expand Down Expand Up @@ -232,7 +233,7 @@ def initialize_dup(obj) # :nodoc:

##
# :method: freeze
# Freeze both the object returned by \_\_getobj\_\_ and self.
# Freeze both the object returned by +__getobj__+ and self.
#
def freeze
__getobj__.freeze
Expand Down