mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
Hash is faster than delegation and simpler to explain
This commit is contained in:
parent
1f0b28b069
commit
3da1104ec3
1 changed files with 3 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
||||||
class Enum < SimpleDelegator
|
class Enum < Hash
|
||||||
# Public: Initialize an enum.
|
# Public: Initialize an enum.
|
||||||
#
|
#
|
||||||
# members - the array of enum members. May contain a hash of options:
|
# 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.
|
# Public: Create a subset of enum, only include specified keys.
|
||||||
def only(*keys)
|
def only(*keys)
|
||||||
dup.tap do |d|
|
dup.tap do |d|
|
||||||
d.__getobj__.keep_if { |k| keys.include?(k) }
|
d.keep_if { |k| keys.include?(k) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Create a subset of enum, preserve all items but specified ones.
|
# Public: Create a subset of enum, preserve all items but specified ones.
|
||||||
def except(*keys)
|
def except(*keys)
|
||||||
dup.tap do |d|
|
dup.tap do |d|
|
||||||
d.__getobj__.delete_if { |k| keys.include?(k) }
|
d.delete_if { |k| keys.include?(k) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue