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

Syntax update #307

Merged
merged 2 commits into from
Jun 24, 2020
Merged

Syntax update #307

merged 2 commits into from
Jun 24, 2020

Conversation

soutaro
Copy link
Member

@soutaro soutaro commented Jun 19, 2020

Update RBS syntax based on the proposal.

  • extension syntax is removed. RBS just ignores it. Use class or module syntax.
  • RBS now allows writing multiple class and module declarations for one class/module.
  • RBS now allows writing class/module/constant/interface/type alias declarations inside class/module declarations.
  • Type name resolution became more compatible with Ruby's constant resolution. It resolves given relative type names based on class/module nesting structure. Note that the type name resolution does not refer inheritance and includes.
  • overload def syntax allows to extend an existing method.
  • super method type is now deprecated. Use overload def syntax.
  • incompatible method attribute is deprecated and ignored.

Example

Before

module RBS
  def self.logger: () -> Logger
end

class RBS::TypeName      # Class decls under a namespace have to be out of module decls.
  ...
end

RBS::VERSION: String     # So is constant decls.

# Use `extension` construct to extend existing classes.
extension Integer (MyNumber)
  def to_my_number: () -> MyNumber  # Add new method

  def +: (MyNumber) -> MyNumber
       | super                                 # Use `super` to extend existing methods.
end

After

module RBS
  def self.logger: () -> Logger

  class TypeName      # Nested class declarations allowed.
    ...
  end

  VERSION: String     # So is constant decls.
end

# Re-open existing classes
class Integer
  def to_my_number: () -> MyNumber  # Add new method

  overload def +: (MyNumber) -> MyNumber  # Use `overload def` to extend existing methods.
end

@soutaro soutaro marked this pull request as ready for review June 24, 2020 06:55
@soutaro soutaro merged commit 503594a into master Jun 24, 2020
@soutaro soutaro deleted the syntax-update branch June 24, 2020 12:26
pocke added a commit to pocke/rbs_rails that referenced this pull request Jun 24, 2020
The last release for RBS with `extension` syntax.
ruby/rbs#307
elishadiah pushed a commit to elishadiah/ROR-mine that referenced this pull request Sep 20, 2022
The last release for RBS with `extension` syntax.
ruby/rbs#307
# 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.

1 participant