Skip to content

Commit

Permalink
Hash is faster than delegation and simpler to explain
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron committed Mar 19, 2013
1 parent 1f0b28b commit 3da1104
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/enum.rb
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -33,14 +33,14 @@ def valid?(member)
# 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

0 comments on commit 3da1104

Please sign in to comment.