GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
made only and except uglier and faster

Calling include? for every key in a long list is hideously slow.

Signed-off-by: Michael S. Klishin <michael@novemberain.com>
granth (author)
Thu May 29 17:46:44 -0700 2008
michaelklishin (committer)
Sun Jun 01 23:24:49 -0700 2008
commit  34b0ccb9db639ed27e6f1158eb712e0c2a8e234c
tree    d3146cb4df6701b93918ee238e8ade9cff18af1a
parent  a70ee65be080740f0f0cbdb08ebfc608596004c6
...
126
127
128
129
 
 
 
130
131
132
...
137
138
139
140
 
 
 
141
142
143
...
126
127
128
 
129
130
131
132
133
134
...
139
140
141
 
142
143
144
145
146
147
0
@@ -126,7 +126,9 @@ class Hash
0
   # { :one => 1, :two => 2, :three => 3 }.only(:one)
0
   # #=> { :one => 1 }
0
   def only(*allowed)
0
- reject { |k,v| !allowed.include?(k) }
0
+ hash = {}
0
+ allowed.each {|k| hash[k] = self[k] }
0
+ hash
0
   end
0
 
0
   # @param *rejected<Array[(String, Symbol)] The hash keys to exclude.
0
@@ -137,7 +139,9 @@ class Hash
0
   # { :one => 1, :two => 2, :three => 3 }.except(:one)
0
   # #=> { :two => 2, :three => 3 }
0
   def except(*rejected)
0
- reject { |k,v| rejected.include?(k) }
0
+ hash = self.dup
0
+ rejected.each {|k| hash.delete(k) }
0
+ hash
0
   end
0
 
0
   # @return <String> The hash as attributes for an XML tag.

Comments