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.
The fourth test test if the date objects are being set up correctly.
@wchargin, I think it's fine to use the ternary ? operator here. Is that what you meant by this isn't very Ruby?
See http://stackoverflow.com/questions/4252936/how-do-i-use-the-conditional-operator-in-ruby
Oh my, please don't apologize! I'm learning a lot from this thread, and I think others are as well.
Thanks @mcclaskc!
I remember having a weird logic problem somewhere which happened because I was using 'and' instead of &&, but I cannot seem to replicate it - my apologies for starting this thread! ><
I agree that 'and' and '&&' have different precedences, and new programmers should not assume 'and' is just a pretty way to say '&&'. That doesn't make the solution incorrect. 'and' still short circuits, so both values have to be true in order for the method to return true. For logical evalutation, the two function the same way.
The problem happens when, like your link says, in when you try to do control flow with '&&', assuming it has the same presedence as 'and'.
For this kata, I really don't see a problem with this solution, but I 100% agree that ruby coders need to be aware of the subtle difference between 'and' and '&&'
haha, you're welcome :)
@surajreddy thanks for the link! I assumed it was a prettier way of writing && and ||...I was way off!
I'll keep that in mind when deciding to use &&/|| or and/or (I mean &&/|| || and/or haha..)
This comment is hidden because it contains spoiler information about the solution
This is not a good solution because "and" should not be used for logic evaluations in Ruby - "and" is a control flow operator, while && is a boolean operator.
See http://devblog.avdi.org/2010/08/02/using-and-and-or-in-ruby/ for more info.
Basically this code seems to work, but continuing to use "and" for boolean logic can create unexpected problems.