andy
andy

Reputation: 2409

Rack 'method not found'

I can't seem to see what's up with this piece of code:

class Cherry
    class << self
        def call env
            self::Application.call
        end
    end
end

class Cherry
    class Application
        def call env
            #Framework logic
        end
    end
end

run Cherry

That's the part of my application that is not working. I have no idea why: NoMethodError at / undefined method 'call' for Cherry::Application:Class

Upvotes: 0

Views: 126

Answers (1)

Chris Cherry
Chris Cherry

Reputation: 28574

You need to adjust a couple of things.

When you are defining the call method inside of Application, you are defining it as an instance method, then you are attempting to call it as a class method, so lets fix the definition to be a class method definition:

class Cherry
    class Application
        def self.call env
            #Framework logic
        end
    end
end

Next there will be a new error, about not passing the right number of arguments to the call method, so we add the env param to where you are calling the call method.

class Cherry
    class << self
        def call env
            self::Application.call env
        end
    end
end

Hope that helps!

Upvotes: 2

Related Questions