Sha256: 15ca8fbb9fd367f3eb43ba7d2f120860a2dc82658cfcf00ac493d9a550a8e4ee
Contents?: true
Size: 1.27 KB
Versions: 6
Compression:
Stored size: 1.27 KB
Contents
module QueenCheck class << self def Arbitrary(name = nil, &block) if block.nil? && !name.nil? return QueenCheck::Arbitrary::Instance.get_by_id(name) else return QueenCheck::Arbitrary::Instance.new(name, &block) end nil end end module Arbitrary class NotQueenCheckArbitrary < StandardError; end def arbitrary?; true; end def arbitrary(seed) raise NotImplementedError end def set_arbitrary(&block) self.module_eval do sig = class << self; self; end sig.send(:define_method, :arbitrary, &block) end end class Instance @@collection = {} def self.get_by_id(name); return @@collection[name.to_s.to_sym]; end def self.collection=(c); @@collection = c; end def self.collection; @@collection; end def initialize(name = nil, &block) raise ArgumentError, "require block" if block.nil? @arbitrary_proc = block @name = name.to_s.to_sym unless name.nil? unless @name.nil? @@collection[@name] = self end end attr_reader :name def arbitrary?; true; end def arbitrary(seed) @arbitrary_proc.call(seed) end end end end class BasicObject def arbitrary?; false; end end
Version data entries
6 entries across 6 versions & 1 rubygems