Friday, May 2, 2014

Quick tidbits

One of the reasons I like Project Euler is that it gives you a chance to expand your knowledge of whatever language you're using...

For instance, today I learned about Fixnum#fdiv (forces float division instead of integer division) in Ruby:
2/4       # 0
2.div(4)  # 0
2.fdiv(4) # 0.5
Sure there's a ton of other ways to do it, but this was succinct and to the point.

And the RSpec =~ operator for array equality - it's basically the same thing as ==, except that order doesn't matter.

[1,2] == [2,1] # false
[1,2] =~ [2,1] # true
Two simple things that I'd not had a reason to use before. Will I use them all the time, nope. But I'm glad to have found them.