views:

64

answers:

1

Just about to extend the Array class with the following extension:

class Array
  def shuffle!
    size.downto(1) { |n| push delete_at(rand(n)) }
    self
  end
end

However, I was wondering where a good place to keep these sort of extensions. I was thinking environment.rb or putting in its own file in the initializers directory.

+6  A: 

I usually follow the ActiveSupport convention, which would be to place them in lib/core_ext/#{class}.rb - in this case, lib/core_ext/array.rb. As John Hyland notes, you can then require the file explicitly where needed, or put a require statement in initializers.

Greg Campbell
This seems like a better answer than mine, so I'm going to delete my answer (and start writing my apps this way).
John Hyland