Project

General

Profile

Feature #14397 ยป return_values_of_visibility_methods.diff

usa (Usaku NAKAMURA), 01/24/2018 09:25 PM

View differences:

spec/ruby/core/main/private_spec.rb (working copy)
11 11
    Object.should have_private_method(:main_public_method)
12 12
  end
13 13

  
14
  it "returns Object" do
15
    eval("private :main_public_method", TOPLEVEL_BINDING).should equal(Object)
14
  ruby_version_is ""..."2.6" do
15
    it "returns Object" do
16
      eval("private :main_public_method", TOPLEVEL_BINDING).should equal(Object)
17
    end
16 18
  end
17 19

  
20
  ruby_version_is "2.6" do
21
    it "returns the argument(s) or Object" do
22
      eval("private :main_public_method", TOPLEVEL_BINDING).should equal(:main_public_method)
23
      eval("private :main_public_method, :main_private_method", TOPLEVEL_BINDING).should eql([:main_public_method, :main_private_method])
24
      eval("private", TOPLEVEL_BINDING).should equal(Object)
25
    end
26
  end
27

  
18 28
  it "raises a NameError when given an undefined name" do
19 29
    lambda do
20 30
      eval "private :main_undefined_method", TOPLEVEL_BINDING
spec/ruby/core/main/public_spec.rb (working copy)
11 11
    Object.should_not have_private_method(:main_private_method)
12 12
  end
13 13

  
14
  it "returns Object" do
15
    eval("public :main_private_method", TOPLEVEL_BINDING).should equal(Object)
14
  ruby_version_is ""..."2.6" do
15
    it "returns Object" do
16
      eval("public :main_private_method", TOPLEVEL_BINDING).should equal(Object)
17
    end
16 18
  end
17 19

  
20
  ruby_version_is "2.6" do
21
    it "returns the argument(s) or Object" do
22
      eval("public :main_private_method", TOPLEVEL_BINDING).should equal(:main_private_method)
23
      eval("public :main_private_method, :main_public_method", TOPLEVEL_BINDING).should eql([:main_private_method, :main_public_method])
24
      eval("public", TOPLEVEL_BINDING).should equal(Object)
25
    end
26
  end
27

  
18 28
  it "raises a NameError when given an undefined name" do
19 29
    lambda do
20 30
      eval "public :main_undefined_method", TOPLEVEL_BINDING
spec/ruby/core/module/private_spec.rb (working copy)
38 38
                  :module_specs_public_method_on_object_for_kernel_private)
39 39
  end
40 40

  
41
  it "returns self" do
42
    (class << Object.new; self; end).class_eval do
43
      def foo; end
44
      private(:foo).should equal(self)
45
      private.should equal(self)
41
  ruby_version_is ""..."2.6" do
42
    it "returns self" do
43
      (class << Object.new; self; end).class_eval do
44
        def foo; end
45
        private(:foo).should equal(self)
46
        private.should equal(self)
47
      end
46 48
    end
47 49
  end
48 50

  
51
  ruby_version_is "2.6" do
52
    it "returns the argument(s) or self" do
53
      (class << Object.new; self; end).class_eval do
54
        def foo; end
55
        def bar; end
56
        private(:foo).should equal(:foo)
57
        private(:foo, :bar).should eql([:foo, :bar])
58
        private.should equal(self)
59
      end
60
    end
61
  end
62

  
49 63
  it "raises a NameError when given an undefined name" do
50 64
    lambda do
51 65
      Module.new.send(:private, :undefined)
spec/ruby/core/module/protected_spec.rb (working copy)
39 39
                  :module_specs_public_method_on_object_for_kernel_protected)
40 40
  end
41 41

  
42
  it "returns self" do
43
    (class << Object.new; self; end).class_eval do
44
      def foo; end
45
      protected(:foo).should equal(self)
46
      protected.should equal(self)
42
  ruby_version_is ""..."2.6" do
43
    it "returns self" do
44
      (class << Object.new; self; end).class_eval do
45
        def foo; end
46
        protected(:foo).should equal(self)
47
        protected.should equal(self)
48
      end
47 49
    end
48 50
  end
49 51

  
52
  ruby_version_is "2.6" do
53
    it "returns the argument(s) or self" do
54
      (class << Object.new; self; end).class_eval do
55
        def foo; end
56
        def bar; end
57
        protected(:foo).should equal(:foo)
58
        protected(:foo, :bar).should eql([:foo, :bar])
59
        protected.should equal(self)
60
      end
61
    end
62
  end
63

  
50 64
  it "raises a NameError when given an undefined name" do
51 65
    lambda do
52 66
      Module.new.send(:protected, :undefined)
spec/ruby/core/module/public_spec.rb (working copy)
27 27
                  :module_specs_private_method_on_object_for_kernel_public)
28 28
  end
29 29

  
30
  it "returns self" do
31
    (class << Object.new; self; end).class_eval do
32
      def foo; end
33
      private :foo
34
      public(:foo).should equal(self)
35
      public.should equal(self)
30
  ruby_version_is ""..."2.6" do
31
    it "returns self" do
32
      (class << Object.new; self; end).class_eval do
33
        def foo; end
34
        private :foo
35
        public(:foo).should equal(self)
36
        public.should equal(self)
37
      end
36 38
    end
37 39
  end
38 40

  
41
  ruby_version_is "2.6" do
42
    it "returns the arugment(s) or self" do
43
      (class << Object.new; self; end).class_eval do
44
        def foo; end
45
        def bar; end
46
        private :foo, :bar
47
        public(:foo).should equal(:foo)
48
        public(:foo, :bar).should eql([:foo, :bar])
49
        public.should equal(self)
50
      end
51
    end
52
  end
53

  
39 54
  it "raises a NameError when given an undefined name" do
40 55
    lambda do
41 56
      Module.new.send(:public, :undefined)
vm_method.c (working copy)
1652 1652
{
1653 1653
    if (argc == 0) {
1654 1654
	rb_scope_visibility_set(visi);
1655
        return module;
1655 1656
    }
1656 1657
    else {
1657 1658
	set_method_visibility(module, argc, argv, visi);
1659
        if (argc == 1) {
1660
            return *argv;
1661
        }
1662
        else {
1663
            return rb_ary_new_from_values(argc, argv);
1664
        }
1658 1665
    }
1659
    return module;
1660 1666
}
1661 1667

  
1662 1668
/*
1663 1669
 *  call-seq:
1664 1670
 *     public                 -> self
1665
 *     public(symbol, ...)    -> self
1666
 *     public(string, ...)    -> self
1671
 *     public(symbol, ...)    -> aSymbol or [symbol, ...]
1672
 *     public(string, ...)    -> sString or [string, ...]
1667 1673
 *
1668 1674
 *  With no arguments, sets the default visibility for subsequently
1669 1675
 *  defined methods to public. With arguments, sets the named methods to
......
1680 1686
/*
1681 1687
 *  call-seq:
1682 1688
 *     protected                -> self
1683
 *     protected(symbol, ...)   -> self
1684
 *     protected(string, ...)   -> self
1689
 *     protected(symbol, ...)   -> aSymbol or [symbol, ...]
1690
 *     protected(string, ...)   -> aString or [string, ...]
1685 1691
 *
1686 1692
 *  With no arguments, sets the default visibility for subsequently
1687 1693
 *  defined methods to protected. With arguments, sets the named methods
......
1707 1713
/*
1708 1714
 *  call-seq:
1709 1715
 *     private                 -> self
1710
 *     private(symbol, ...)    -> self
1711
 *     private(string, ...)    -> self
1716
 *     private(symbol, ...)    -> aSymbol or [symbol, ...]
1717
 *     private(string, ...)    -> aString or [string, ...]
1712 1718
 *
1713 1719
 *  With no arguments, sets the default visibility for subsequently
1714 1720
 *  defined methods to private. With arguments, sets the named methods