46
spooky
7y

5 likes and I’ll merge /dev/null into master

Comments
  • 15
    class Rant {
    function self.++() {
    if (self.rating < 5) {
    return self.rating += 1;
    }
    self.comment("Ey!");
    }
    }
  • 20
  • 6
    @Ashkin Does that mean that you comment Ey for every vote more than 5?
  • 1
    @romangraef it means that she always deliver a Ey! On rants that she ++ ;)
  • 3
    @mngr No since she returns if self.rating < 5
  • 1
    @romangraef oh, you are right!
  • 1
    @mngr @romangraef hmm, look at the brackets though.
    Every time the function is called from a rant, if the rant's value is <5, she adds a ++ to it and returns that.
    If that doesn't happen, she comments "Ey!" (And the function doesn't return? O.o)
  • 8
    @endor Exactly. But don't bother understanding it.. It seems to be JavaScript
  • 4
    @romangraef new life motto
  • 2
    Lol.
    She is commenting "Ey" only when self.rating is NOT under 5 anymore. And that is it. It does NOT repeat!
  • 2
    @gitpull Except there's another call to operator++
  • 4
    @romangraef
    There is no second call to ++, what are you talking about? 😞

    It overrides the class,
    Redefines the ++ func,
    Increments only when < 5 (to keep it at 5),
    and comments "Ey!" otherwise.

    And since it overrides the class, all following ++'s/comments should have respected it ☹

    That way OP can't say "but the rant got 12, not 5!" and fail to deliver.

    @endor
    It returns on +=1 because I assume that's the default functionality of ++. Anything that modifies a value should return that value. Commenting, by contrast, doesn't touch the rant's rating, and therefore wouldn't return it.

    However since I'm redefining ++, the comment section should also return the rating since I'm assuming that's the original behavior of ++. Anything that modifies a value should return that value. Oops :<
  • 1
    @Ashkin i meant if someone else calls ++()
  • 1
    @romangraef
    Intended to apply to everyone 😉
  • 1
    @Ashkin yeah, it's the lack of a return statement in the second case that was confusing me. Stil, nice function! :)
Add Comment