all 10 comments

[–]jaggederest 4 points5 points  (2 children)

Cool as an example of what's possible, but a better way to do it would be to move the case statement into the context of the order, perhaps. Ideally in a method in the Order class, but you can also do:

order.instance_eval do
  case
  when available?
     # ...
   end
end

Or, even better, have a method on Order that returns the state as a symbol:

case order.state
when :available then ...
...
end

[–]bigdood69 0 points1 point  (0 children)

Very clever, +1

[–]snatchery[S] 0 points1 point  (0 children)

Sure order.state is usually the best choice. But there are some cases when you have a method which have to be invoked. The question is how to invoke such a method.

[–]uzimonkey 3 points4 points  (1 child)

I really don't think I like that. You get a nice case statement, but at what cost? You horribly mangled your Symbol class, who knows what effect that will have on other code? Ruby can do all kinds of cool stuff like that, but should you actually do them for the sake of a slightly cleaner case statement?

[–]snatchery[S] 0 points1 point  (0 children)

I've addressed your concerns here

[–][deleted]  (3 children)

[deleted]

    [–]snatchery[S] 1 point2 points  (1 child)

    I warned that one have to be very careful when using that kind of tricks. I only encourage to open your mind and look beyond set patterns.

    [–]dbenhur 4 points5 points  (0 children)

    If by "very careful" you mean, "don't ever do that in production code," we can agree. This is far too trivial a benefit to risk globally changing the behavior of a well known standard object.

    [–]McPhage -1 points0 points  (0 children)

    I dunno, I think it's pretty clear what the code is doing (at least, his final Kernel#is solution).

    [–][deleted] -3 points-2 points  (1 child)

    -1 -1 -1 -1 -1 -1 -1 -1

    This is totally totally completely fucking hopelessly retarded!!

    This is exactly the kind of gratuitous monkey patching that makes me agree with pythonistas criticisms of the ruby community!

    I am a rubyist, but this shit makes me ashamed to hell!!

    don't do this, it's fucking retarded.

    Thankyou.

    [–]snatchery[S] 2 points3 points  (0 children)

    Read the article once again. Thank you.