Skip to content
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

Support alias in rbs prototype rb #457

Merged
merged 2 commits into from
Nov 1, 2020

Conversation

pocke
Copy link
Member

@pocke pocke commented Nov 1, 2020

This pull request makes rbs prototype rb to support alias.

Currently rbs prototype rb just ignores alias syntax and alias_method. It will output alias by this change.

For example:

# test.rb

class C
  def m() end
  alias m2 m
end
# Before
$ rbs prototype rb test.rb
class C
  def m: () -> nil
end

# after
$ rbs prototype rb test.rb
class C
  def m: () -> nil

  alias m2 m
end

@@ -166,9 +178,9 @@ def process(node, decls:, comments:, singleton:)
end
when :attr_reader
args.each do |arg|
if arg&.type == :LIT && arg.children[0].is_a?(Symbol)
if arg && (name = literal_to_symbol(arg))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not the main part of this pull request, but attr_* accept Strings as a method names. It is the same behavior with alias_method.
So I changed them to accept Strings.

class C
  attr_reader 'a'
  attr_writer 'a'
  attr_accessor 'b'
end

c = C.new

c.a = 1
c.b = 2
p c.a, c.b
# => 1
     2

f8accb0

Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@soutaro soutaro merged commit 8247716 into ruby:master Nov 1, 2020
@pocke pocke deleted the alias-in-rbs-prototype-rb branch November 1, 2020 12:43
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants