-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Make Kernel methods to be available as module functions #549
Make Kernel methods to be available as module functions #549
Conversation
Well, this change doesn't affect the accessibility of The accessibility is still $ exe/rbs method --singleton Kernel puts
::Kernel.puts
defined_in: ::Kernel
implementation: ::Kernel
accessibility: private
types:
(*untyped arg0) -> ::NilClass I guess the cause is a mismatch of Ruby's module_function and RBS's In Ruby, module_function works as the following:
But in RBS, I guess So, I think we have two solutions to fix this problem. First, we can define private instance methods and public singleton methods by hand. # kernel.rbs
module Kernel : BasicObject
private
def puts: (*untyped) -> nil
public
def self.puts: (*untyped) -> nil
# ...
end It works, but I think it is not efficient. Second, we can change the semantics of module M
private
def self?.foo: () -> untyped
end
# M.foo is public or private??? |
07e9da3
to
515475e
Compare
| [T] (::Array[T] x) -> ::Array[T] | ||
| [T] (::Range[T] x) -> ::Array[T] | ||
| [K, V] (::Hash[K, V] x) -> ::Array[[K, V]] | ||
| [T] (T x) -> ::Array[T] | ||
|
||
def Complex: (Numeric | String x, ?Numeric | String y, ?exception: bool exception) -> Complex | ||
def self?.Complex: (Numeric | String x, ?Numeric | String y, ?exception: bool exception) -> Complex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Goodcheck] Prefer
boolish
overbool
for method arguments and block return values (view)See the doc below:
https://github.com/ruby/rbs/blob/78d04a2db0f1c4925d2b13c2939868edf9465d6c/docs/syntax.md#bool-or-boolish
Rule rbs.prefer_boolish
You can close this issue if no need to fix it. Learn more.
👍 true
of false
is required here.
| (String arg, ?Integer base, ?exception: bool exception) -> Integer | ||
|
||
def Rational: (Numeric | String | Object x, ?Numeric | String y, ?exception: bool exception) -> Rational | ||
def self?.Rational: (Numeric | String | Object x, ?Numeric | String y, ?exception: bool exception) -> Rational |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Goodcheck] Prefer
boolish
overbool
for method arguments and block return values (view)See the doc below:
https://github.com/ruby/rbs/blob/78d04a2db0f1c4925d2b13c2939868edf9465d6c/docs/syntax.md#bool-or-boolish
Rule rbs.prefer_boolish
You can close this issue if no need to fix it. Learn more.
I closed this issue, because:
- When you strictly want
true | false
.
515475e
to
6ae39a8
Compare
core/kernel.rbs
Outdated
@@ -54,7 +54,7 @@ module Kernel : BasicObject | |||
# try { "hello" } #=> "hello" | |||
# try do "hello" end #=> "hello" | |||
# ``` | |||
def block_given?: () -> bool | |||
def self?.block_given? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved the conflict caused by deletion of iterator?
#569
6ae39a8
to
6aec641
Compare
This pull request makes Kernel methods to be available as module functions.
Problem
Most
Kernel
methods are available as module functions, but currently anyKernel
methods aren't.For example,
Kernel.puts "Hello"
is a valid Ruby code but Steep complain it.Because
Kernel.puts
is typed as a private method accidentally.Solution
Most methods are module functions, but it is not all methods. So I need to extract the target methods in the beginning.
I extracted the target methods with the following code on IRB.
And I changed the methods kinds to
self?
for the above methods.Note
I found some missing methods while I updated the RBS.
The following methods are available as Kernel's singleton methods, but RBS doesn't have any definitions.
So we need to add them to
kernel.rbs
as module functions, but this pull request doesn't add them because of out of scope.I'll work on them with another pull request.
--
I noticed this problem with this bloc post. Thanks! https://narazaka.hatenablog.jp/entry/2020/12/26/Ruby_3.0%E3%81%AE%E9%9D%99%E7%9A%84%E5%9E%8B%E5%AE%9A%E7%BE%A9%E3%82%92TypeScript%E3%81%BF%E3%81%9F%E3%81%84%E3%81%AB%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA%E3%81%AB%E6%9B%B8%E3%81%84%E3%81%A6