Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions language/defined_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,22 @@
}.should complain(/warning: possibly useless use of defined\? in void context/, verbose: true)
end
end

describe "for a protected method" do
it "returns 'method' when the receiver is a subclass instance" do
DefinedSpecs::ProtectedBase.new.defined_on(DefinedSpecs::ProtectedSubclass.new).should == "method"
end

it "returns 'method' when the receiver is the base class instance" do
DefinedSpecs::ProtectedSubclass.new.defined_on(DefinedSpecs::ProtectedBase.new).should == "method"
end

ruby_bug "#22076", ""..."4.1" do
it "returns 'method' when the receiver is a sibling class instance via a shared included module" do
DefinedSpecs::ProtectedIncluderA.new.defined_on(DefinedSpecs::ProtectedIncluderB.new).should == "method"
end
end
end
end

describe "The defined? keyword for an expression" do
Expand Down
27 changes: 27 additions & 0 deletions language/fixtures/defined.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,33 @@ def method_no_args
super
end
end

class ProtectedBase
def m; end
protected :m
def defined_on(o)
defined?(o.m)
end
end

class ProtectedSubclass < ProtectedBase
end

module ProtectedInModule
def m; end
protected :m
def defined_on(o)
defined?(o.m)
end
end

class ProtectedIncluderA
include ProtectedInModule
end

class ProtectedIncluderB
include ProtectedInModule
end
end

class Object
Expand Down
Loading