Skip to content

Commit 0cf9b30

Browse files
authored
feat: Object のメソッドを定義 (#19)
* feat: `Object` のメソッドを定義 * feat: テストを追加 * chore: `==`, `!=` を `Object` からの継承に変更 * chore: rubocop
1 parent 3fcf006 commit 0cf9b30

5 files changed

Lines changed: 184 additions & 12 deletions

File tree

core/float.rbs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ class Float < Object
1313

1414
def **: (Integer | Float) -> Float
1515

16-
def ==: (untyped other) -> bool
17-
18-
def !=: (untyped other) -> bool
19-
2016
def <: (Integer | Float other) -> bool
2117

2218
def <=: (Integer | Float other) -> bool

core/integer.rbs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ class Integer < Object
3434

3535
def >>: (Integer) -> Integer
3636

37-
def ==: (untyped other) -> bool
38-
39-
def !=: (untyped other) -> bool
40-
4137
def <: (Integer | Float other) -> bool
4238

4339
def <=: (Integer | Float other) -> bool

core/object.rbs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,92 @@
11
class Object < BasicObject
2+
def !: () -> bool
3+
def self.!: () -> bool
4+
5+
def !=: (untyped other) -> bool
6+
def self.!=: (untyped other) -> bool
7+
8+
def <=>: (untyped other) -> bool
9+
def self.<=>: (untyped other) -> bool
10+
11+
def ==: (untyped other) -> bool
12+
def self.==: (untyped other) -> bool
13+
14+
def ===: (untyped other) -> bool
15+
def self.===: (untyped other) -> bool
16+
17+
def <: (untyped other) -> bool
18+
19+
def <=: (untyped other) -> bool
20+
21+
def >: (untyped other) -> bool
22+
23+
def >=: (untyped other) -> bool
24+
25+
def class: () -> class
26+
def self.class: () -> self
27+
28+
def dup: () -> self
29+
def self.dup: () -> self
30+
31+
def block_given?: () -> bool
32+
33+
# TODO: Module
34+
def kind_of?: (Class) -> bool
35+
def self.kind_of?: (Class) -> bool
36+
37+
alias is_a? kind_of?
38+
alias self.is_a? self.kind_of?
39+
40+
def nil?: () -> bool
41+
def self.nil?: () -> bool
42+
43+
# TODO: Array
44+
def p: () -> nil
45+
| [T](T arg0) -> T
46+
47+
def print: (*untyped args) -> nil
48+
49+
def puts: (*untyped args) -> nil
50+
51+
# TODO Exception
52+
def raise: () -> bot
53+
| (String message) -> bot
54+
# | (Exception) -> bot
55+
# | (singleton(Exception)) -> bot
56+
# | (Exception, String message) -> bot
57+
# | (singleton(Exception), String message) -> bot
58+
59+
# TODO: Symbol
60+
# def self.attr_reader: (*String names) -> void
61+
62+
# TODO: Symbol
63+
# def self.attr_accessor: (*Symbol names) -> void
64+
65+
# TODO: Module
66+
# def include: (*Module mods) -> void
67+
# def self.include: (*Module mods) -> void
68+
#
69+
# alias extend include
70+
# alias self.extend include
71+
72+
# TODO: Array, Symbol
73+
# def self.constants: (?bool inherit) -> Array[Symbol]
74+
75+
def self.public: () -> void
76+
77+
def self.private: () -> void
78+
79+
def self.protected: () -> void
80+
81+
def sprintf: (String format, *untyped args) -> String
82+
83+
def printf: (String format, *untyped args) -> nil
84+
85+
def to_s: () -> String
86+
def self.to_s: () -> String
87+
88+
alias inspect to_s
89+
alias self.inspect self.to_s
90+
91+
def loop: () { () -> void } -> bot
292
end

core/string.rbs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
class String < Object
22
def initialize: (?String source) -> void
33

4-
def ==: (untyped other) -> bool
5-
6-
def !=: (untyped other) -> bool
7-
84
def <: (String other) -> bool
95

106
def <=: (String other) -> bool

test/object.rb

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,95 @@
11
# frozen_string_literal: true
2+
3+
# rubocop:disable Lint/Void
4+
# rubocop:disable Lint/UnreachableCode
5+
# rubocop:disable Lint/UselessAccessModifier
6+
# rubocop:disable Style/CaseEquality
7+
# rubocop:disable Style/ClassCheck
8+
# rubocop:disable Style/FormatString
9+
# rubocop:disable Style/RedundantFormat
10+
11+
object = Object.new
12+
13+
!object
14+
!Object
15+
16+
object != true
17+
Object != true
18+
19+
object <=> true
20+
Object <=> true
21+
22+
object == true
23+
Object == true
24+
25+
object === true
26+
Object === true
27+
28+
object < 1
29+
30+
object <= 1
31+
32+
object > 1
33+
34+
object >= 1
35+
36+
object.class
37+
Object.class
38+
39+
object.dup
40+
Object.dup
41+
42+
block_given?
43+
object.block_given?
44+
45+
object.kind_of? Object
46+
Object.kind_of? Object
47+
48+
object.is_a? Object
49+
Object.is_a? Object
50+
51+
object.nil?
52+
Object.nil?
53+
54+
p
55+
p 1
56+
object.p
57+
object.p 1
58+
59+
print
60+
print 1, true, 'a'
61+
object.print
62+
object.print 1, true, 'a'
63+
64+
puts
65+
puts 1, true, 'a'
66+
object.puts
67+
object.puts 1, true, 'a'
68+
69+
raise
70+
raise 'error'
71+
object.raise
72+
object.raise 'error'
73+
74+
# @type const A: A
75+
class A
76+
public
77+
78+
private
79+
80+
protected
81+
end
82+
83+
sprintf "%d\n", 123
84+
85+
printf "%d\n", 123
86+
87+
object.to_s
88+
Object.to_s
89+
90+
object.inspect
91+
Object.inspect
92+
93+
loop { puts }
94+
95+
# rubocop:enable all

0 commit comments

Comments
 (0)