Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Root797347yclass Rant {
function self.++() {
if (self.rating < 5) {
return self.rating += 1;
}
self.comment("Ey!");
}
} -
endor56707y@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) -
Lol.
She is commenting "Ey" only when self.rating is NOT under 5 anymore. And that is it. It does NOT repeat! -
Root797347y@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 :< -
endor56707y@Ashkin yeah, it's the lack of a return statement in the second case that was confusing me. Stil, nice function! :)
5 likes and I’ll merge /dev/null into master
joke/meme