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

Allow additional optional and rest arguments in classes that implement interfaces #1

Merged
merged 2 commits into from
Apr 19, 2024

Conversation

Verseth
Copy link
Contributor

@Verseth Verseth commented Apr 19, 2024

Hi, I noticed that method signature need to match exactly when using interfaces.
I found it quite annoying since some libraries define getter methods with additional unused rest arguments eg. ActiveRecord::Attributes. This means that I would have to define the interface with additional rest arguments and also add those rest arguments to regular manual getters in other classes.

This PR allows classes that implements interfaces to define additional optional or rest arguments.

module InterfaceOne
  def foo(a, b); end
  def bar(a); end
end

class KlassOne
  extend Interfaceable
  implements InterfaceOne

  # this will be accepted
  def foo(a, b, c = 4); end

  # this will be accepted as well
  def bar(a, *args, **kwargs); end
end

module InterfaceTwo
  def foo(a, b, c = 5); end
  def bar(a, *args); end
end

class KlassTwo
  extend Interfaceable
  implements InterfaceTwo

  # this will not be accepted
  def foo(a, b); end

  # this is invalid
  def bar(a); end
end

@artemave
Copy link
Member

This looks good to me. The only thing, I would add new tests (where applicable) rather than adding to the existing ones.

@artemave
Copy link
Member

Oh, and please also update the readme.

@Verseth
Copy link
Contributor Author

Verseth commented Apr 19, 2024

Sure, I've just added new test cases and updated the readme

@artemave artemave merged commit 34d2da4 into featurist:master Apr 19, 2024
2 checks passed
@artemave
Copy link
Member

Thank you for your pr. I pushed an updated version of the gem.

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