Sha256: 5bb99ba614296957c67f83d23b3dd4f0aef6adf3ca53bee8f60fe60fdc074a4f
Contents?: true
Size: 670 Bytes
Versions: 10
Compression:
Stored size: 670 Bytes
Contents
module Mutations class DuckFilter < AdditionalFilter @default_options = { :nils => false, # true allows an explicit nil to be valid. Overrides any other options :methods => nil # The object needs to respond to each of the symbols in this array. } def filter(data) # Handle nil case if data.nil? return [nil, nil] if options[:nils] return [nil, :nils] end # Ensure the data responds to each of the methods Array(options[:methods]).each do |method| return [data, :duck] unless data.respond_to?(method) end # We win, it's valid! [data, nil] end end end
Version data entries
10 entries across 10 versions & 1 rubygems