@@ -105,10 +105,9 @@ def initialize(source_buffer,
105105 @source_buffer = source_buffer
106106 @in_transaction = false
107107
108- @policy = { crossing_deletions : crossing_deletions ,
109- different_replacements : different_replacements ,
110- swallowed_insertions : swallowed_insertions } . freeze
111- check_policy_validity
108+ @policy = { crossing_deletions : check_policy_value ( crossing_deletions ) ,
109+ different_replacements : check_policy_value ( different_replacements ) ,
110+ swallowed_insertions : check_policy_value ( swallowed_insertions ) } . freeze
112111
113112 @enforcer = method ( :enforce_policy )
114113 # We need a range that would be jugded as containing all other ranges,
@@ -361,10 +360,11 @@ def insert_after_multi(range, text)
361360
362361 private
363362
364- ACTIONS = %i[ accept warn raise ] . freeze
365- def check_policy_validity
366- invalid = @policy . values - ACTIONS
367- raise ArgumentError , "Invalid policy: #{ invalid . join ( ', ' ) } " unless invalid . empty?
363+ ACTIONS = %i[ accept warn raise ] . to_set . freeze
364+ def check_policy_value ( value )
365+ raise ArgumentError , "Invalid policy value: #{ value } " unless ACTIONS . include? ( value )
366+
367+ value
368368 end
369369
370370 def combine ( range , attributes )
0 commit comments