TypeError: Coerce must return [x, y] in the methods exercises

Hello,

I’m trying to complete the methods exercises and running into the following error:

`1) methods.rb int_remainder_without_modulo doesn’t use the % operator
Failure/Error: return (i_divisor * dec_remainder_of_two_integers(i_dividend, i_divisor)).round.to_i

 TypeError:
   coerce must return [x, y]
 # ./lib/methods.rb:107:in `*'
 # ./lib/methods.rb:107:in `int_remainder_without_modulo'
 # ./spec/methods_spec.rb:144:in `block (3 levels) in <top (required)>'`

I’ve looked through other topics on this error but I haven’t been able to resolve it. My best understanding is that coerce is being called on an object, I assume what my method is returning, but that object can’t coerce, resulting in a typeError. The final method called on my return value is to_i, and from my poking around in documentation on coerce, integers should have the method. I can paste my code if needed but I’m not sure what the rules on that are.
To the best of my knowledge none of the methods called use modulo, including the dec_remainder_of_two_floats and dec_remainder_of_two_integers, but I do use the floor method. Does this use %1 and would that be enough to trip this final test? Is there a place where I can see the code being used in ruby’s built in methods?

Hi @Agiel,

There’s an issue with how that particular test is written, go ahead and move on :slight_smile:

If you take a look at the spec file, you’ll see that for that test, we aren’t passing in an integer like we might expect. We’re passing in a null object so that we can see what methods have or haven’t been called on it. THe null object is throwing off some of the basic integer method calls, specifically, *

Understood, thank you! Just for my own understanding I want to see if I have this right:
The object is a double, something set up to behave sort of like an integer for testing purposes, which we have made null to avoid complications in errors (is this some sort of blanket allow for messages to the double?). When we multiply ruby needs to coerce the double to an int to make sure we’re multiplying like types, but this doesn’t work for some reason and the whole thing throws an error.

That’s essentially correct!