Project

General

Profile

Feature #8499

Updated by mrkn (Kenta Murata) over 11 years ago

=begin RD 
 According to my experiences, the following two idioms often appeare in application codes. 

 (1) (({hash = other_hash.select { |k, | [:key1, :key2, :key3].include? k }})) 
 (2) (({hash = other_hash.reject { |k, | [:key1, :key2, :key3].include? k }})) 

 On Rails, they can be written in the following forms by using ActiveSupport's features. 

 (1) (({hash = other_hash.slice(:key1, :key2, :key3)})) 
 (2) (({hash = other_hash.except(:key1, other_hash.reject(:key1, :key2, :key3)})) 

 I think the latter forms are shorter and more readable than the former ones. 

 So I propose to import the following methods from ActiveSupport: 

 * (({Hash#slice})) 
 * (({Hash#slice!})) 
 * (({Hash#except})) 
 * (({Hash#except!})) 
 =end

Back