Weird initializer #99

nyarly opened this Issue Feb 7, 2013 · 6 comments


None yet

4 participants

nyarly commented Feb 7, 2013

Is there something wrong with subclasses of Resource having to do

  def initialize(request, response)
    super # or super(request, response) if changing signature


bernd commented Feb 8, 2013

Subclasses of Resource do not have to call super. The Webmachine::Resource does not define an initialize method. You can just use it like this.

class Res < Webmachine::Resource
  def initialize
    # do stuff here

Not sure if this answers your question. :)

ghost commented Feb 8, 2013

If changing the signature I prefer not having to deal with handling the response & request arguments.


@robgleeson That is exactly why Webmachine does not do as @nyarly suggests. I expect it would be error-prone to require the user to know that the request and response objects would be passed to the initializer. Besides, how often do you actually use the initialize method in a Rails controller? Generally you don't, you use the actions or before/around filters.

nyarly commented Feb 10, 2013

I got what was going on in the Resource::new method, I'm just not convinced it's as good an idea as all that.

You're comparing Webmachine to Rails? 😦 Granted, I can't put my finger on my misgivings, apart from a general precept of meta-programming as little as possible. I think part of this is that it's the first step of making request/response "magic" things, as opposed to completely normal ivars.

I'll definitely call into question the idea that it might be confusing to have a programmer not understand basic behaviors of the language, e.g. class inheritance. "Because Rails..." makes me very sad.


Just using the Rails controller as an example, there are other relevant ones.

Sure, it is a fine line to walk. As it is, Webmachine tends to be more on the "less magic" side, but this feels very minor to me.


I agree that resource initialization is unconventional, but I don't believe the current behavior is worth changing.

@nyarly nyarly closed this Nov 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment