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

Fixing Module#refine type signature #1064

Merged

Conversation

piotaixr
Copy link
Contributor

The Module#refine should allow to pass a Module to refine, and not only classes, as the following is legal:

module A
  refine Enumerable do
    def test
      42
    end
  end
end

Also:

  • refine accepts a block but does not provide any argument to it
  • refine returns an instance of Refinement
a = module A
  refine String do |arg|
    puts arg.class
  end
end
puts a.class
# NilClass
# Refinement
# => nil

@piotaixr piotaixr force-pushed the feature/refine-accepts-module-not-only-class branch from 3a4b87c to cfcff13 Compare July 16, 2022 13:48
Comment on lines +84 to +90
if spy_block
return_value = spy.object.__send__(spy.method_name, *args) do |*a, **k, &b|
spy_block.call(*a, **k, &b)
end
else
return_value = spy.object.__send__(spy.method_name, *args, &spy_block)
end
Copy link
Contributor Author

@piotaixr piotaixr Jul 16, 2022

Choose a reason for hiding this comment

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

This to go around the fact that the ruby source seems to require the block given to refine have to be a proper block a not a Proc.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks.

I would skip the test rather than adding this code, but we can do that when this actually causes a problem. 💪

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 added this to the RBS 2.7.0 milestone Aug 4, 2022
@soutaro soutaro merged commit 058244a into ruby:master Aug 4, 2022
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