Module: ObjectOculus::Methods

Included in:
Object
Defined in:
lib/object_oculus/methods.rb

Overview

The methods added to all objects by object_oculus

Instance Method Summary collapse

Instance Method Details

#__clone__Object

Make sure cloning doesn’t cause anything to fail via type errors



60
# File 'lib/object_oculus/methods.rb', line 60

alias __clone__ clone

#cloneObject

Adds in a type error check to the default Object#clone method to prevent any interruptions while checking methods. If a TypeError is encountered, self is returned



64
65
66
67
68
# File 'lib/object_oculus/methods.rb', line 64

def clone
  __clone__
rescue TypeError
  self
end

#given(*args) ⇒ Object

Provides a list of arguments that will be used when trying to find matching methods.

5.given(1).what_equals 6
# => 5 + 1 == 6


8
9
10
11
12
13
14
15
# File 'lib/object_oculus/methods.rb', line 8

def given(*args)
  if frozen?
    FrozenSection.new(self, args:)
  else
    @args = args
    self
  end
end

#methods_by_ancestorObject

Lists all methods available to the object by ancestor



53
54
55
56
57
# File 'lib/object_oculus/methods.rb', line 53

def methods_by_ancestor
  ([self] + self.class.ancestors).each_with_object({}) do |object, result|
    result[object] = object.unique_methods
  end
end

#unique_methodsObject

The list of all methods unique to an object



48
49
50
# File 'lib/object_oculus/methods.rb', line 48

def unique_methods
  methods - self.class.methods
end

#what_equals(expected_result) ⇒ Object

Outputs a list of methods and their values that equal an expected_result, allowing for some coercion (e.g. 5 == 5.0)



19
20
21
# File 'lib/object_oculus/methods.rb', line 19

def what_equals(expected_result, ...)
  show_methods(expected_result, {}, ...)
end

#what_matches(expected_result) ⇒ Object

Outputs a list of methods and their values that match an expected_result, which is coerced into a regular expression if it’s not already one



30
31
32
# File 'lib/object_oculus/methods.rb', line 30

def what_matches(expected_result, ...)
  show_methods(expected_result, { force_regex: true }, ...)
end

#what_works_withObject Also known as: what_works

Outputs a list of all methods and their values



35
36
37
# File 'lib/object_oculus/methods.rb', line 35

def what_works_with(...)
  show_methods(nil, { show_all: true }, ...)
end

#whats_exactly(expected_result) ⇒ Object

Outputs a list of methods and their values that exactly equal an expected_result



24
25
26
# File 'lib/object_oculus/methods.rb', line 24

def whats_exactly(expected_result, ...)
  show_methods(expected_result, { force_exact: true }, ...)
end

#whats_not_blank_withObject Also known as: whats_not_blank

Outputs a list of all methods and their values, provided they are not blank (nil, false, undefined, empty)



42
43
44
# File 'lib/object_oculus/methods.rb', line 42

def whats_not_blank_with(...)
  show_methods(nil, { show_all: true, exclude_blank: true }, ...)
end