Skip to content

Commit 57986c6

Browse files
authored
Merge pull request #2362 from ksss/top-level-self-class
Add type `RBS::Unnamed::TopLevelSelfClass` to core
2 parents 1b24957 + 78216ae commit 57986c6

2 files changed

Lines changed: 174 additions & 0 deletions

File tree

core/rbs/unnamed/main_class.rbs

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
module RBS
2+
module Unnamed
3+
class TopLevelSelfClass
4+
private
5+
6+
# <!--
7+
# rdoc-file=eval.c
8+
# - include(module, ...) -> self
9+
# -->
10+
# Invokes Module.append_features on each parameter in reverse order.
11+
#
12+
%a{annotate:rdoc:copy:Module#include}
13+
def include: (Module, *Module arg0) -> self
14+
15+
# <!--
16+
# rdoc-file=eval.c
17+
# - using(module) -> self
18+
# -->
19+
# Import class refinements from *module* into the current class or module
20+
# definition.
21+
#
22+
%a{annotate:rdoc:copy:Module#using}
23+
def using: (Module arg0) -> self
24+
25+
# <!--
26+
# rdoc-file=proc.c
27+
# - define_method(symbol, method) -> symbol
28+
# - define_method(symbol) { block } -> symbol
29+
# -->
30+
# Defines an instance method in the receiver. The *method* parameter can be a
31+
# `Proc`, a `Method` or an `UnboundMethod` object. If a block is specified, it
32+
# is used as the method body. If a block or the *method* parameter has
33+
# parameters, they're used as method parameters. This block is evaluated using
34+
# #instance_eval.
35+
#
36+
# class A
37+
# def fred
38+
# puts "In Fred"
39+
# end
40+
# def create_method(name, &block)
41+
# self.class.define_method(name, &block)
42+
# end
43+
# define_method(:wilma) { puts "Charge it!" }
44+
# define_method(:flint) {|name| puts "I'm #{name}!"}
45+
# end
46+
# class B < A
47+
# define_method(:barney, instance_method(:fred))
48+
# end
49+
# a = B.new
50+
# a.barney
51+
# a.wilma
52+
# a.flint('Dino')
53+
# a.create_method(:betty) { p self }
54+
# a.betty
55+
#
56+
# <em>produces:</em>
57+
#
58+
# In Fred
59+
# Charge it!
60+
# I'm Dino!
61+
# #<B:0x401b39e8>
62+
#
63+
%a{annotate:rdoc:copy:Module#define_method}
64+
def define_method: (interned symbol, ^(?) [self: top] -> untyped | Method | UnboundMethod method) -> Symbol
65+
| (interned symbol) { (?) [self: top] -> untyped } -> Symbol
66+
67+
# <!--
68+
# rdoc-file=vm_method.c
69+
# - public -> nil
70+
# - public(method_name) -> method_name
71+
# - public(method_name, method_name, ...) -> array
72+
# - public(array) -> array
73+
# -->
74+
# With no arguments, sets the default visibility for subsequently defined
75+
# methods to public. With arguments, sets the named methods to have public
76+
# visibility. String arguments are converted to symbols. An Array of Symbols
77+
# and/or Strings is also accepted. If a single argument is passed, it is
78+
# returned. If no argument is passed, nil is returned. If multiple arguments are
79+
# passed, the arguments are returned as an array.
80+
#
81+
%a{annotate:rdoc:copy:Module#public}
82+
def public: () -> nil
83+
| (Symbol method_name) -> Symbol
84+
| (Symbol, Symbol, *Symbol method_name) -> Array[Symbol]
85+
| (string method_name) -> string
86+
| (interned, interned, *interned method_name) -> Array[interned]
87+
| (Array[interned]) -> Array[interned]
88+
89+
# <!--
90+
# rdoc-file=vm_method.c
91+
# - private -> nil
92+
# - private(method_name) -> method_name
93+
# - private(method_name, method_name, ...) -> array
94+
# - private(array) -> array
95+
# -->
96+
# With no arguments, sets the default visibility for subsequently defined
97+
# methods to private. With arguments, sets the named methods to have private
98+
# visibility. String arguments are converted to symbols. An Array of Symbols
99+
# and/or Strings is also accepted. If a single argument is passed, it is
100+
# returned. If no argument is passed, nil is returned. If multiple arguments are
101+
# passed, the arguments are returned as an array.
102+
#
103+
# module Mod
104+
# def a() end
105+
# def b() end
106+
# private
107+
# def c() end
108+
# private :a
109+
# end
110+
# Mod.private_instance_methods #=> [:a, :c]
111+
#
112+
# Note that to show a private method on RDoc, use <code>:doc:</code>.
113+
#
114+
%a{annotate:rdoc:copy:Module#private}
115+
def private: () -> nil
116+
| (Symbol method_name) -> Symbol
117+
| (Symbol, Symbol, *Symbol method_name) -> Array[Symbol]
118+
| (string method_name) -> string
119+
| (interned, interned, *interned method_name) -> Array[interned]
120+
| (Array[interned]) -> Array[interned]
121+
end
122+
end
123+
end
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require_relative "test_helper"
2+
3+
# Instantiate the pseudo class
4+
module RBS
5+
module Unnamed
6+
end
7+
end
8+
RBS::Unnamed::TopLevelSelfClass = self.class
9+
TopLevelSelf = self
10+
def top_level_self_method1 = 1
11+
def top_level_self_method2 = 2
12+
13+
class TopLevelSelfTest < Test::Unit::TestCase
14+
include TestHelper
15+
16+
testing "::RBS::Unnamed::TopLevelSelfClass"
17+
18+
def test_include
19+
assert_send_type "(Module) -> RBS::Unnamed::TopLevelSelfClass",
20+
TopLevelSelf, :include, Module.new
21+
end
22+
23+
def test_define_method
24+
assert_send_type "(Symbol) { () -> void } -> Symbol",
25+
TopLevelSelf, :define_method, :foo do end
26+
assert_send_type "(Symbol, ^() -> void) -> Symbol",
27+
TopLevelSelf, :define_method, :foo, -> {}
28+
end
29+
30+
def test_public
31+
assert_send_type "() -> nil",
32+
TopLevelSelf, :public
33+
assert_send_type "(Symbol) -> Symbol",
34+
TopLevelSelf, :public, :top_level_self_method1
35+
assert_send_type "(Symbol, Symbol) -> [Symbol, Symbol]",
36+
TopLevelSelf, :public, :top_level_self_method1, :top_level_self_method2
37+
assert_send_type "([Symbol, Symbol]) -> [Symbol, Symbol]",
38+
TopLevelSelf, :public, [:top_level_self_method1, :top_level_self_method2]
39+
end
40+
41+
def test_private
42+
assert_send_type "() -> nil",
43+
TopLevelSelf, :private
44+
assert_send_type "(Symbol) -> Symbol",
45+
TopLevelSelf, :private, :top_level_self_method1
46+
assert_send_type "(Symbol, Symbol) -> [Symbol, Symbol]",
47+
TopLevelSelf, :private, :top_level_self_method1, :top_level_self_method2
48+
assert_send_type "([Symbol, Symbol]) -> [Symbol, Symbol]",
49+
TopLevelSelf, :private, [:top_level_self_method1, :top_level_self_method2]
50+
end
51+
end

0 commit comments

Comments
 (0)