diff --git a/core/object.rbs b/core/object.rbs index b41c297..8feb2e3 100644 --- a/core/object.rbs +++ b/core/object.rbs @@ -55,11 +55,9 @@ class Object < BasicObject # | (Exception, String message) -> bot # | (singleton(Exception), String message) -> bot - # TODO: Symbol - # def self.attr_reader: (*String names) -> void + def self.attr_reader: (*Symbol names) -> void - # TODO: Symbol - # def self.attr_accessor: (*Symbol names) -> void + def self.attr_accessor: (*Symbol names) -> void def include: (Module, *Module mods) -> void def self.include: (Module, *Module mods) -> void @@ -67,7 +65,7 @@ class Object < BasicObject alias extend include alias self.extend self.include - # TODO: Array, Symbol + # TODO: Array # def self.constants: (?bool inherit) -> Array[Symbol] def self.public: () -> void diff --git a/core/string.rbs b/core/string.rbs index 1abbd72..f114871 100644 --- a/core/string.rbs +++ b/core/string.rbs @@ -79,10 +79,9 @@ class String < Object def strip!: () -> self? - # TODO: Symbol - # def to_sym: () -> Symbol - # - # alias intern to_sym + def to_sym: () -> Symbol + + alias intern to_sym def tr: (String pattern, String replace) -> String diff --git a/core/symbol.rbs b/core/symbol.rbs new file mode 100644 index 0000000..5299ba3 --- /dev/null +++ b/core/symbol.rbs @@ -0,0 +1,14 @@ +class Symbol < Object + # TODO: Array + # def self.all_symbols: () -> Array[Symbol] + + def inspect: () -> String + def self.inspect: () -> String + + def to_s: () -> String + def self.to_s: () -> String + + alias id2name to_s + + def to_sym: () -> Symbol +end diff --git a/test/object.rb b/test/object.rb index 7914663..b0c2281 100644 --- a/test/object.rb +++ b/test/object.rb @@ -3,11 +3,13 @@ # rubocop:disable Lint/Void # rubocop:disable Lint/UnreachableCode # rubocop:disable Lint/UselessAccessModifier +# rubocop:disable Lint/DuplicateMethods # rubocop:disable Style/CaseEquality # rubocop:disable Style/ClassCheck # rubocop:disable Style/FormatString # rubocop:disable Style/RedundantFormat # rubocop:disable Style/MixinGrouping +# rubocop:disable Style/AccessorGrouping # rubocop:disable Layout/EmptyLinesAroundAccessModifier # @type const TestMod: Module @@ -82,6 +84,12 @@ module TestMod end # @type const A: Class class A + attr_reader :foo + attr_reader :foo, :bar, :baz + + attr_accessor :foo + attr_accessor :foo, :bar, :baz + # @type const TestMod: Module module TestMod end diff --git a/test/string.rb b/test/string.rb index ff41d9d..ae593cd 100644 --- a/test/string.rb +++ b/test/string.rb @@ -2,6 +2,7 @@ # rubocop:disable Lint/Void # rubocop:disable Lint/RedundantTypeConversion +# rubocop:disable Lint/SymbolConversion # rubocop:disable Style/StringConcatenation String.new @@ -85,6 +86,10 @@ ' abcdef '.strip! +'abcdef'.to_sym + +'abcdef'.intern + 'abcdef'.tr 'a-z', 'n-za-m' 'abcdef'.tr! 'a-z', 'n-za-m' diff --git a/test/symbol.rb b/test/symbol.rb new file mode 100644 index 0000000..a2b4dcf --- /dev/null +++ b/test/symbol.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# rubocop:disable Lint/SymbolConversion +# rubocop:disable Lint/RedundantTypeConversion + +:foo.inspect +Symbol.inspect + +:foo.to_s +Symbol.to_s + +:foo.id2name + +:foo.to_sym + +# rubocop:enable all