mirror of
https://github.com/PeterCamilleri/fOOrth
synced 2024-11-16 07:47:56 +01:00
Begin overhaul of dyadic ops. New coerce protocols.
This commit is contained in:
parent
b569f07cba
commit
fa41b0130e
2 changed files with 35 additions and 0 deletions
|
@ -38,6 +38,19 @@ class Object
|
|||
raise XfOOrth::ForceAbort, msg
|
||||
end
|
||||
|
||||
#Argument coercion methods. These are stubs.
|
||||
|
||||
#Coerce the argument to match my type. Stub
|
||||
def foorth_coerce(_arg)
|
||||
error "Cannot coerce to a #{self.foorth_name}"
|
||||
end
|
||||
|
||||
#Coerce the argument to match my type with min/max support. Stub
|
||||
def foorth_mnmx_coerce(_arg)
|
||||
error "Cannot min/max coerce to a #{self.foorth_name}"
|
||||
end
|
||||
|
||||
|
||||
#New math methods. The mnmx_ prefix is short for min_max_.
|
||||
#These methods handle the default case for non-numeric data.
|
||||
|
||||
|
|
22
tests/monkey_patch/coerce_test.rb
Normal file
22
tests/monkey_patch/coerce_test.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# coding: utf-8
|
||||
|
||||
require_relative '../../lib/fOOrth/monkey_patch'
|
||||
require 'minitest/autorun'
|
||||
require 'minitest_visible'
|
||||
|
||||
#Test the monkey patches applied to the coerce protocol.
|
||||
class CoerceProtocolTester < MiniTest::Unit::TestCase
|
||||
|
||||
#Track mini-test progress.
|
||||
MinitestVisible.track self, __FILE__
|
||||
|
||||
#Test that it embeds
|
||||
def test_obect_stubs
|
||||
obj = Object.new
|
||||
|
||||
assert_raises(XfOOrth::XfOOrthError) { obj.foorth_coerce(42) }
|
||||
assert_raises(XfOOrth::XfOOrthError) { obj.foorth_mnmx_coerce(42) }
|
||||
end
|
||||
|
||||
|
||||
end
|
Loading…
Reference in a new issue