mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
Hash is faster than delegation and simpler to explain
This commit is contained in:
parent
1f0b28b069
commit
3da1104ec3
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user