Looking for the answers to Ruby Koans? Well you’re not going to get them here! But what I will do is show you how to get them and who to ask if you get stuck.
If you’re anything like me, you’re probably thinking the answers are harder than what they actually are – or that perhaps the questions are trick questions! But they’re not, all you need to do is just answer the questions in the simplest possible form.
For example, you’re asked if nil is an object:
assert_equal __, nil.is_a?(Object), "Unlike NULL in other languages"
end
And all you have to do is answer the question (but in Ruby terms). Is nil an object? The answer of course is yes – so in Ruby language, that is ‘true’.
In fact if you get stuck Ruby will even give you the answers, open IRB and ask away:
And it will say:
Here’s another example:
assert_equal __, 123.to_s
assert_equal __, nil.to_s
end
And the answers are:
assert_equal "123", 123.to_s
assert_equal "", nil.to_s
end
Enjoy!