Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby 3.1: Add {Method,UnboundMethod}#{public?,private?,protected?} #955

Merged
Merged
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
6 changes: 6 additions & 0 deletions core/method/fixtures/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ def one_req_one_opt_with_splat_and_block(a, b=nil, *c, &blk); end
def two_req_one_opt_with_splat_and_block(a, b, c=nil, *d, &blk); end
def one_req_two_opt_with_splat_and_block(a, b=nil, c=nil, *d, &blk); end

def my_public_method; end
def my_protected_method; end
def my_private_method; end
protected :my_protected_method
private :my_private_method

define_method(:zero_defined_method, Proc.new {||})
define_method(:zero_with_splat_defined_method, Proc.new {|*x|})
define_method(:one_req_defined_method, Proc.new {|x|})
Expand Down
21 changes: 21 additions & 0 deletions core/method/private_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

ruby_version_is "3.1" do
describe "Method#private?" do
it "returns false when the method is public" do
obj = MethodSpecs::Methods.new
obj.method(:my_public_method).private?.should == false
end

it "returns false when the method is protected" do
obj = MethodSpecs::Methods.new
obj.method(:my_protected_method).private?.should == false
end

it "returns true when the method is private" do
obj = MethodSpecs::Methods.new
obj.method(:my_private_method).private?.should == true
end
end
end
21 changes: 21 additions & 0 deletions core/method/protected_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

ruby_version_is "3.1" do
describe "Method#protected?" do
it "returns false when the method is public" do
obj = MethodSpecs::Methods.new
obj.method(:my_public_method).protected?.should == false
end

it "returns true when the method is protected" do
obj = MethodSpecs::Methods.new
obj.method(:my_protected_method).protected?.should == true
end

it "returns false when the method is private" do
obj = MethodSpecs::Methods.new
obj.method(:my_private_method).protected?.should == false
end
end
end
21 changes: 21 additions & 0 deletions core/method/public_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

ruby_version_is "3.1" do
describe "Method#public?" do
it "returns true when the method is public" do
obj = MethodSpecs::Methods.new
obj.method(:my_public_method).public?.should == true
end

it "returns false when the method is protected" do
obj = MethodSpecs::Methods.new
obj.method(:my_protected_method).public?.should == false
end

it "returns false when the method is private" do
obj = MethodSpecs::Methods.new
obj.method(:my_private_method).public?.should == false
end
end
end
6 changes: 6 additions & 0 deletions core/unboundmethod/fixtures/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def neg_four(a, b, *c, &d); end

def discard_1(); :discard; end
def discard_2(); :discard; end

def my_public_method; end
def my_protected_method; end
def my_private_method; end
protected :my_protected_method
private :my_private_method
end

class Parent
Expand Down
21 changes: 21 additions & 0 deletions core/unboundmethod/private_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

ruby_version_is "3.1" do
describe "UnboundMethod#private?" do
it "returns false when the method is public" do
obj = UnboundMethodSpecs::Methods.new
obj.method(:my_public_method).unbind.private?.should == false
end

it "returns false when the method is protected" do
obj = UnboundMethodSpecs::Methods.new
obj.method(:my_protected_method).unbind.private?.should == false
end

it "returns true when the method is private" do
obj = UnboundMethodSpecs::Methods.new
obj.method(:my_private_method).unbind.private?.should == true
end
end
end
21 changes: 21 additions & 0 deletions core/unboundmethod/protected_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

ruby_version_is "3.1" do
describe "UnboundMethod#protected?" do
it "returns false when the method is public" do
obj = UnboundMethodSpecs::Methods.new
obj.method(:my_public_method).unbind.protected?.should == false
end

it "returns true when the method is protected" do
obj = UnboundMethodSpecs::Methods.new
obj.method(:my_protected_method).unbind.protected?.should == true
end

it "returns false when the method is private" do
obj = UnboundMethodSpecs::Methods.new
obj.method(:my_private_method).unbind.protected?.should == false
end
end
end
21 changes: 21 additions & 0 deletions core/unboundmethod/public_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

ruby_version_is "3.1" do
describe "UnboundMethod#public?" do
it "returns true when the method is public" do
obj = UnboundMethodSpecs::Methods.new
obj.method(:my_public_method).unbind.public?.should == true
end

it "returns false when the method is protected" do
obj = UnboundMethodSpecs::Methods.new
obj.method(:my_protected_method).unbind.public?.should == false
end

it "returns false when the method is private" do
obj = UnboundMethodSpecs::Methods.new
obj.method(:my_private_method).unbind.public?.should == false
end
end
end