Skip to content

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

@duduribeiro

Description

@duduribeiro

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions