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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with Ruby 3 when extending Sinatra::Base #1669

Closed
duduribeiro opened this issue Dec 17, 2020 · 3 comments 路 Fixed by #1670
Closed

Incompatibility with Ruby 3 when extending Sinatra::Base #1669

duduribeiro opened this issue Dec 17, 2020 · 3 comments 路 Fixed by #1670

Comments

@duduribeiro
Copy link
Contributor

Hey Folks 馃憢

I'm trying to upgrade an app to test with Ruby 3 and I'm having a problem.

This is the minimal example to reproduce it:

class Foo < Sinatra::Base
  def initialize(app:, comp:)
    p app
    p comp
  end
end

The Class Foo extends from Sinatra::Base and I redefine the initializer to accept two named parameter and it fails with this error:

 Foo.new(app: 1, comp: 2)
ArgumentError: wrong number of arguments (given 1, expected 0; required keywords: app, comp)
from (pry):3:in `initialize

I think the problem is inside the new redefinition here https://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L1525-L1528

      def new(*args, &bk)
        instance = new!(*args, &bk)
        Wrapper.new(build(instance).to_app, instance)
      end

I tried to fork the sinatra code and change this method to be accepted as the new ruby 3 pattern https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
but I failed without breaking the original behave.

any ideas on what to do here?

I'm thinking on redefine new instead of creating an initializer as a workaround for this.

Thanks

@dentarg
Copy link
Member

dentarg commented Dec 17, 2020

I failed without breaking the original behave.

What did you try? What failed? Did you use ruby2_keywords?

@duduribeiro
Copy link
Contributor Author

@dentarg I was having problem keeping the compatibility with keywords / positional arguments. When implemented for one it broke another one 馃槃 . I was able to resolve this and will open a PR with a possible solution.

Thanks

@duduribeiro
Copy link
Contributor Author

I failed without breaking the original behave.

What did you try? What failed? Did you use ruby2_keywords?

and no, I wasn't using ruby2_keywords on my project. I was trying to investigate if I could fix this on sinatra::base

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 a pull request may close this issue.

2 participants