Module: KitchenSink
- Defined in:
- lib/kitchen.rb
Overview
Used to create one of “everything”, where everything includes objects that can be instantiated with no arguments
Defined Under Namespace
Classes: KitchenSinkError
Constant Summary collapse
- Version =
'0.0.3'
Instance Method Summary collapse
-
#edge_cases_for(klass) ⇒ Object
Returns an array of common edge cases for a specified class
klass
. -
#everything ⇒ Object
Returns one of each object instantiated with it’s default value.
-
#everything_but(klass) ⇒ Object
Returns one of everything except the type specified (as a class)
klass
. -
#everything_that_cannot(method) ⇒ Object
Returns one of everything that cannot respond to the method
method
. -
#everything_that_cannot_be_coerced_into(klass) ⇒ Object
(also: #everything_that_aint)
Returns one of everything that cannot be coereced into a specified class
klass
.
Instance Method Details
#edge_cases_for(klass) ⇒ Object
Returns an array of common edge cases for a specified class klass
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/kitchen.rb', line 67 def edge_cases_for(klass) objects = [] case when klass == String objects = %w[ "", " ", "\", "'", "`"] when klass == Array objects = [[], [1], [""], [0], [10000000000], [Class]] when klass == Hash objects = [{1 => nil}, {2=>[]}, {3 => "a"}, {4 => 0}, {}] end return objects end |
#everything ⇒ Object
Returns one of each object instantiated with it’s default value
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/kitchen.rb', line 12 def everything objects = [] ObjectSpace.each_object(Class) do |c| if c.methods.include?('new') begin m = c.method(:new) o = m.call if m.arity == -1 objects.push(o) rescue ArgumentError, ThreadError, TypeError end end end objects end |
#everything_but(klass) ⇒ Object
Returns one of everything except the type specified (as a class) klass
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/kitchen.rb', line 29 def everything_but(klass) begin unless klass.is_a?(Class) raise KitchenSinkError , "#{klass} isn't a Class" end rescue NoMethodError raise KitchenSinkError, "#{klass} isn't a Class" end objects = everything objects.delete_if do |o| o.kind_of?(klass) end end |
#everything_that_cannot(method) ⇒ Object
Returns one of everything that cannot respond to the method method
45 46 47 48 49 50 |
# File 'lib/kitchen.rb', line 45 def everything_that_cannot(method) objects = everything objects.delete_if do |o| o.respond_to?(method) end end |
#everything_that_cannot_be_coerced_into(klass) ⇒ Object Also known as: everything_that_aint
Returns one of everything that cannot be coereced into a specified class klass
54 55 56 57 58 59 60 61 62 |
# File 'lib/kitchen.rb', line 54 def everything_that_cannot_be_coerced_into(klass) objects = everything objects.delete_if do |o| begin klass.new(o) rescue end end end |