Class: Method
- Inherits:
-
Object
- Object
- Method
- Defined in:
- lib/method_extensions.rb
Instance Attribute Summary collapse
-
#inline_tests ⇒ Object
Returns the value of attribute inline_tests.
Instance Method Summary collapse
-
#[](*parameters) ⇒ Object
Expose a shorthand for .call.
- #run_inline_tests ⇒ Object
Instance Attribute Details
#inline_tests ⇒ Object
Returns the value of attribute inline_tests.
2 3 4 |
# File 'lib/method_extensions.rb', line 2 def inline_tests @inline_tests end |
Instance Method Details
#[](*parameters) ⇒ Object
Expose a shorthand for .call
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/method_extensions.rb', line 5 def [](*parameters) homogenized_parameters = homogenized_list_of_arrays(parameters) permutation_lookup = {} all_range_permutations = permutations_of_list_of_ranges(homogenized_parameters) all_range_permutations.each do |parameter_permutation| permutation_lookup[parameter_permutation] = call(*parameter_permutation) end should_reduce_results = permutation_lookup.values.uniq.count == 1 if should_reduce_results permutation_lookup.values.first else permutation_lookup end end |
#run_inline_tests ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/method_extensions.rb', line 23 def run_inline_tests # TODO: this is probably a good place to manage per-test state, reset DB if needed, etc # Gem users should be able to use assert(), assert_equal(), etc in their test blocks, but # I don't want to pollute the global namespace, so we instantiate a TestHelper (which contains # all of those methods) and run each block of inline texts within that TestHelper's context, # meaning they can use assert(true) in their test blocks anywhere without having to litter # Kernel with global methods OR require people to do something like TestHelper::assert(true). testhelper = TestHelper.new testhelper.method = self testhelper.fuzz = self testhelper.instance_exec(&inline_tests) if inline_tests && inline_tests.respond_to?(:call) end |