Module: WhatsUp::Methods
- Included in:
- Object
- Defined in:
- lib/whats_up/methods.rb
Overview
The methods added to all objects by whats_up
Instance Method Summary collapse
-
#__clone__ ⇒ Object
Make sure cloning doesn’t cause anything to fail via type errors.
-
#clone ⇒ Object
Adds in a type error check to the default Object#clone method to prevent any interruptions while checking methods.
-
#given(*args) ⇒ Object
Provides a list of arguments that will be used when trying to find matching methods.
-
#methods_by_ancestor ⇒ Object
Lists all methods available to the object by ancestor.
-
#unique_methods ⇒ Object
The list of all methods unique to an object.
-
#what_equals(expected_result, *args, &block) ⇒ Object
Outputs a list of methods and their values that equal an
expected_result
, allowing for some coercion (e.g.5 == 5.0
). -
#what_matches(expected_result, *args, &block) ⇒ 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. -
#what_works_with(*args, &block) ⇒ Object
(also: #what_works)
Outputs a list of all methods and their values.
-
#whats_exactly(expected_result, *args, &block) ⇒ Object
Outputs a list of methods and their values that exactly equal an
expected_result
. -
#whats_not_blank_with(*args, &block) ⇒ Object
(also: #whats_not_blank)
Outputs a list of all methods and their values, provided they are not blank (nil, false, undefined, empty).
Instance Method Details
#__clone__ ⇒ Object
Make sure cloning doesn’t cause anything to fail via type errors
62 |
# File 'lib/whats_up/methods.rb', line 62 alias_method :__clone__, :clone |
#clone ⇒ Object
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
66 67 68 69 70 |
# File 'lib/whats_up/methods.rb', line 66 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/whats_up/methods.rb', line 8 def given(*args) if frozen? FrozenSection.new self, args: args else @args = args self end end |
#methods_by_ancestor ⇒ Object
Lists all methods available to the object by ancestor
53 54 55 56 57 58 59 |
# File 'lib/whats_up/methods.rb', line 53 def methods_by_ancestor result = {} ([self] + self.class.ancestors).each do |object| result[object] = object.unique_methods end result end |
#unique_methods ⇒ Object
The list of all methods unique to an object
48 49 50 |
# File 'lib/whats_up/methods.rb', line 48 def unique_methods methods - self.class.methods end |
#what_equals(expected_result, *args, &block) ⇒ 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/whats_up/methods.rb', line 19 def what_equals(expected_result, *args, &block) show_methods expected_result, {}, *args, &block end |
#what_matches(expected_result, *args, &block) ⇒ 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/whats_up/methods.rb', line 30 def what_matches(expected_result, *args, &block) show_methods expected_result, { force_regex: true }, *args, &block end |
#what_works_with(*args, &block) ⇒ Object Also known as: what_works
Outputs a list of all methods and their values
35 36 37 |
# File 'lib/whats_up/methods.rb', line 35 def what_works_with(*args, &block) show_methods nil, { show_all: true }, *args, &block end |
#whats_exactly(expected_result, *args, &block) ⇒ Object
Outputs a list of methods and their values that exactly equal an expected_result
24 25 26 |
# File 'lib/whats_up/methods.rb', line 24 def whats_exactly(expected_result, *args, &block) show_methods expected_result, { force_exact: true }, *args, &block end |
#whats_not_blank_with(*args, &block) ⇒ Object 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/whats_up/methods.rb', line 42 def whats_not_blank_with(*args, &block) show_methods nil, { show_all: true, exclude_blank: true }, *args, &block end |