Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit generating duplicate method by rbs prototype rb #334

Merged
merged 1 commit into from
Jul 20, 2020

Conversation

pocke
Copy link
Member

@pocke pocke commented Jul 12, 2020

Problem

Sometimes we define the same methods with different bodies. For example:

class C
  if RUBY_VERSION >= '2.7'
    def foo
      do_something_27
    end
  else
    def foo
      do_something
    end
  end
end

But rbs prototype rb generates exactly the same foo method twice.

$ exe/rbs prototype rb test.rb
class C
  def foo: () -> untyped

  def foo: () -> untyped
end

So I need to remove one of the methods manually.

We can find this situation from Active Support codebase.
For example: https://github.com/rails/rails/blob/fbe2433be6e052a1acac63c7faf287c52ed3c5ba/activesupport/lib/active_support/option_merger.rb#L30-L43

Solution

Omit to generate duplicate method if the same method is already generated.

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 d5f32a2 into ruby:master Jul 20, 2020
@pocke pocke deleted the omit-duplicate-methods branch July 20, 2020 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants