Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Ternary at the end isn't needed, just use the empty check.
You need to make the tests public to clarify the intent of the problem. It's unnecessarily vague honestly.
Reduce would be cleaner.
Then it'd just be a polish / reverse polish stack calculator like a good number of 6th kyu runs.
Mine's pretty straightforward as well. Reduce takes operators as symbols, which is incredibly useful in this case.
You can use the index to make the numbers more succinct.
In Ruby, reduce can take operators as symbols, making this a very easy solution to implement. Just wait until the second number is added, and you just need to get them out of the stack and reduce using the given operator.
Now, if we wanted to stream this along a little bit more I would keep returning self on the number methods regardless and define == to give the head value of the stack. That's most of the reason I bothered with a stack is I thought the test cases might pull shenanigans on that account and stream numbers. Guess not.
Doing the checking, with proper detailed feedback leads to a better understanding of the language and syntax. But this test fixture is frustrating in its opacity.
My solution should fail with two negative inputs, but it doesn't.
In Ruby, you shouldn't do pointless things like Type Checking when trying to convey a point or do an exercise. You want people to get the math, not the catch-all nonsense. Abstract it out.