Ad
  • Custom User Avatar

    You are damn right! This is not the best practice guy. Please, be responsible and dont vote for best practices.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Nice solution, didnt know about Enumerable#grep

  • Custom User Avatar

    @cu6upb like monking said, the real problem is that your editing something that's not yours (the global string object) Which means that if somone imports your library it would at worst break their code because you've changed the way the string behaves.

    It is ok however to use prototypal inheritance to make your own sub-objects and those you can edit to your hearts desire. I've never tried to do it with a built in type (besides Object) but I bet you can.

  • Custom User Avatar

    By editing a built-in prototype, you're assuming that by the time you need it, nobody else has done the same thing that you just did (but perhaps they figured "capitallize" would output 'nIfTy'). You're opening your code to error, or introducing error into someone else's code.

  • Default User Avatar

    Hi, I don't know a lot of about javascript but why adding to String's prototype is bad practice? Are you talking about creating new constructor instead of using string prototype? Thank you)

  • Custom User Avatar

    Yeah I don't really come from the Javascript world. Even in my native Ruby, this would be monkey patching of a core class and not a good idea.

  • Default User Avatar

    I agree with the above comments but accidently clicked the 'Best practices' button...doh!

  • Default User Avatar

    Augmenting built-in types' prototypes is definitely not a best practice.

  • Custom User Avatar

    Clever although I would say adding onto String's prototype is bad practice.