From 3da1104ec3c007ca07b67481da71ecd30d687463 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 19 Mar 2013 16:08:25 -0700 Subject: [PATCH] Hash is faster than delegation and simpler to explain --- lib/enum.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/enum.rb b/lib/enum.rb index 8bb7cece2..bbdc3fe82 100644 --- a/lib/enum.rb +++ b/lib/enum.rb @@ -1,4 +1,4 @@ -class Enum < SimpleDelegator +class Enum < Hash # Public: Initialize an enum. # # members - the array of enum members. May contain a hash of options: @@ -33,14 +33,14 @@ class Enum < SimpleDelegator # Public: Create a subset of enum, only include specified keys. def only(*keys) dup.tap do |d| - d.__getobj__.keep_if { |k| keys.include?(k) } + d.keep_if { |k| keys.include?(k) } end end # Public: Create a subset of enum, preserve all items but specified ones. def except(*keys) dup.tap do |d| - d.__getobj__.delete_if { |k| keys.include?(k) } + d.delete_if { |k| keys.include?(k) } end end end