Ruby Quirks
For Ruby 1.9.3, 2.0.x, 2.1.x, 2.2.x
Introduction
ruby_quirks
is a gem which adds a collection of optional Ruby hotfixes and common idioms to accommodate for some of Ruby's quirky behaviors. See the list below to see what's offered.
Hotfixes
Hash#reject and Hash#select returns Hash for subclasses of Hash
-
For Ruby versions: 2.2.0+
-
Description: Calling
#reject
or#select
against an instance of a class that inherits fromHash
will return an object of typeHash
, rather than an object of the same type that#reject
or#select
was called against. e.g. This broke Rails'HashWithIndifferentAccess
. See this question for more details. -
What this hotfix does: It overrides
#reject
and#select
of implementing classes to use#dup
to return an object of the same type. This effectively replicates pre-2.2 behavior ofHash
. -
How to implement: Include the
RubyQuirks::Hash::EnumByDup
in your class that inherits fromHash
-
Example:
module CustomHash < Hash include RubyQuirks::Hash::EnumByDup end
Changelog
Version 0.0.2
- Fixed: Namespace not loading (whoops!)
Version 0.0.1
- Initial version of Ruby Quirks
- Added:
RubyQuirks::Hash::EnumByDup