Skip to content

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

Open
HoneyryderChuck wants to merge 4 commits intoruby:masterfrom
HoneyryderChuck:delegate
Open

(delegate) Sigs for delegate + proposal for delegator defs in RBS #765
HoneyryderChuck wants to merge 4 commits intoruby:masterfrom
HoneyryderChuck:delegate

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.

@HoneyryderChuck HoneyryderChuck force-pushed the delegate branch 3 times, most recently from 96dbb69 to 5e1fa6a Compare August 25, 2021 12:57
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants