Unlocking The Power Of Case Equality: Proc#===
Range, Class and Regexp all implement their own version of ===, so why not Proc?
Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!
Range, Class and Regexp all implement their own version of ===, so why not Proc?
Comments
You can shortcut
multiples_of_5 = Proc.new{|*parameters| parameters.map{|i| i.modulo(5).zero?}.all?}tomultiples_of_5 = Proc.new{|*parameters| parameters.all? { |i| i.modulo(5).zero?}}Better and IMO nicer. regards
Thanks for the shortcut. We’ve changed that line to your version.
Post a comment