In this very specific case, I think an edit would have been more appropriate, but in general, deriving answers from other answers, and giving a self-answer deriving from another answer with adjustments to show one's (the asker's) final solution is allowed, and it is not "very rude behaviour".
Now that I've reached 10k rep and can see deleted posts, I can see that their self-answer is mostly the same as the answer it derives from (yours), except that it adds back some contextual code that was there in their question post. That's why I think an edit to your post would have been appropriate.
This same question/topic has essentially been covered six times already- three times on meta.stackexchange.com (2011, 2012, 2014), and three times on meta.stackoverflow.com (2014, 2015, 2019). All those older Q&A have fairly highly upvoted answers saying that in general, this is not unacceptable behaviour.
I.e., there is a stronger, longer-standing precedent that such behaviour is not unacceptable or rude.
Here are those posts and their verdicts:
What to do if an asker makes a self-answer based on a previously-accepted other answer? (MSE 2012)
This Q&A itself should satisfy the discussion here. It covers three different cases of "augmented answers":
If the answer differs substantially from the originally accepted answer, or combines several different answers into a single one, then I don't see a problem. The OP apparently found his answer more useful.
If the new answer is essentially the same as the original answer, I would leave a comment stating that you feel it is bad form to hijack someone else's answer, and downvote his new answer.
If it's basically a copy/paste of another answer without attribution (crediting the original author), you can flag for removal, citing plagiarism.
- @user102937
Addition to answer. Self answer or comment? (MSO 2019)
Self-answer. Your addition is a standalone response to the answer. Be sure to add attribution to whoever provided most of the answer for you. - @Makoto
I’d accept the other answer, upvote it, then post your own answer, which should start out immediately and explicitly saying “Building on @OtherUser’s very helpful answer (link to his answer), I created a more complete solution this: ...”. That way credit where credit is due, and the community benefits also from a more comprehensive answer, while giving the original answer the head start it earned. - @Dan Bron
What's the right way to self-answer if other answers assisted? (MSO 2014)
A bit contrary to Dan Bron, this post with lots of upvotes says:
Marking an answer as accepted is supposed to represent that that answer ultimately solved your problem. Marking an answer that did not solve your problem (and leaving it that way) will mislead future users who are also having the same problem, and are trying to find a solution.
What I would do in your case is to just link to the other person's answer, mentioning that their answer inspired yours, and other people may give it a few upvotes then. You can even make your own answer into a community wiki, if you feel that you personally don't deserve any reputation from upvotes for (partially) using someone else's idea. - @user456814
Is it appropriate to answer one's own question with code derived from another answer? (MSE 2011)
If the user gives credit to the sources, why not? At first I thought they might be gaming the system for points, but since that isn't what's happening, it should be OK. - @Caffeinated
It is actually a pretty common scenario that the answers help resolve the question but don't show the whole picture. So I actually consider it good if the OP posts the complete solution that resolved his problem again. Of course only as long as he credits sources for this solution. - @WladimirPalant
OP answers his/her own question without acknowledging the help (MSE 2014)
There's really nothing wrong with this. The author of the first answer didn't edit the changes into his own answer, so I think it's perfectly within reason for the OP to post their own answer with a working example. - @BillTheLizard
Important note: I find that answer incomplete because it should really say that the self-answer in question should attribute sources where appropriate/necessary.
Should I include the working code after I have resolved an issue using more than one of the answers? (MSO 2015)
I would indeed suggest to post an own answer. Give attribution to the users you derived an answer from and make sure it is more than just a code dump of the working code. The answer should really stand on its own.
I would also suggest accepting the answer that helped you best if your work is a derivative from that answer, not your own. An exception can be made if your post is much better than the work you derived your answer from.
Never post working code as a comment or an edit of your question. That isn't the place for answers.
- @PatrickHofman
To sum up, in general, this is ok as long as they attribute the existing answer they based their self-answer off of. Contributed content here on Stack Exchange is all licensed under CC-BY-SA. Yes, they do have the option to edit the existing answer and collaborate with the author of the existing answer to get it up to where they'd like it to be, but as far as I'm aware, there is no official rule or community-accepted guideline that says they have to. And remember that edits should not change the meaning of the post or conflict with the original author's intent, so there are actually a lot of things you can't do in an edit that you can do by posting a new derivative answer.
I can't say that if someone made an "augmented", properly attributed version of an answer I wrote and got a bunch of rep for it, I wouldn't be irked. Of coursed I'd be a little irked: I would rather have them edit my answer so I can get more fake internet points! But unless there's a strong case for the augmented answer to be an edit to my hypothetical answer (such as the augmentation being very minor and not diverging from the intent/meaning of my post), I would have to let it be because it's allowed. I would hold no grudges, and neither would I think of the augmenter as rude. Any rep they get for it would technically be deserved, since they provided value that the other answer didn't, and remember that there's nothing stopping the other answerer from augmenting their own answer based on the derivative answer to make even further improvements as long as it follows the CC-BY-SA license.
If the self-answer is an exact copy with no attribution (or even with attribution), obviously, it should be flagged.