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

(delegate) Sigs for delegate + proposal for delegator defs in RBS #765

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

HoneyryderChuck
Copy link
Contributor

@HoneyryderChuck HoneyryderChuck commented Aug 24, 2021

(tentative) added support for inheriting from delegator classes

By defining such RBS classes such as:

    class Tempfile < Delegator[File]
    ...

with this patch, while building the instance definition, the class
assigned to the Delegator definition is then merged with the main
class definitions, which achieves the purpose of inheriting method
definitions from the delegated class.

This is a solution based on a stdlib definition however, so it might not
be the best way to move forward.

By defining such RBS classes such as:

```ruby
class Tempfile < Delegator[File]
...
```

with this patch, while building the instance definition, the class
assigned to the Delegator definition is then merged with the main
class definitions, which achieves the purpose of inheriting method
definitions from the delegated class.

This is a solution based on a stdlib definition however, so it might not
be the best way to move forward.
end

module Kernel
def self?.DelegateClass: [A] (Class superclass) ?{ () -> singleton(Delegator) } -> singleton(Delegator)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally this should be:

def self?.DelegateClass: [A] (Class superclass) ?{ () -> singleton(Delegator[A]) } -> singleton(Delegator[A])

but the parser can't recognize singleton(Delegator[A]).

@soutaro add this along to the other caveats in the description.

@HoneyryderChuck
Copy link
Contributor Author

@soutaro given the recent additions in 2.0 around bounded generics, shall we revisit this? I think we still need special syntax for this, i.e. smth like:

class Delegator[T]
  @delegate_sd_obj: T

  # some rbs syntax to say "inherit API from T?
...

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