Ad
  • Default User Avatar

    sort_by uses an unstable quicksort so any chars being sorted by the size of the ordering string are not quaranteed to retain their position among other unsorted chars.

  • Default User Avatar

    I think an example (like you used) that demonstrates the potential issue is a good way to do it. It's marginally more difficult but maybe not enough to change the ranking.

    If you wanted to make it more difficult you could come up with some story why you need to reimplement OpenStruct to have read-only attributes, but as it stands it's a good way to show the unintended side effects of metaprogramming!

  • Default User Avatar

    How about adding this to the end of your tests:

    Test.expect(!dog.respond_to?(:engine))