Dissecting Code With Ruby's Caller Method

Here is a short snippet of code that has become one of my favourite debugging tools recently. It’s not efficient, definitely not elegant, but man is it useful. location = caller.first location = location[0...location.rindex(":")] line_number = location[(location.rindex(":")+1)..-1] file = location[0...location.rindex(":")] puts location puts File.open(file).readlines[line_number.to_i - 1] puts "#{values}" puts "--"*20 But let’s back up a moment, how did I get to this stage? Background As part of consultancy work we often inherit applications developed by other Rails shops of varying quality.

Diving into the Ruby Source Code: Understanding Ruby's Bigdecimal Rounding Options

If you’re a developer and I ask you about numeric rounding, you’d probably think of something like this: Jump to the decimal place that we are rounding to Look at the digit to the right of it Based on that digit and our rounding rule, make a decision We can round up if we see non-zero in that spot (also known as “ceil”), or we can round down regardless of the digit (aka “floor” or truncate), or we can round >= 5 up and truncate if < 5 (banker’s rounding).

Fixing Native Datepickers in Turbolinks Android Apps

Some client apps make use of Turbolinks-Android to provide a native Android experience for their Rails web apps. This is fine until you try to use something like an HTML5 date field. When the user taps on the field they get… nothing. No datepicker, not even a keyboard, just a flashing cursor trapped in a forever-empty field. This is a known issue with Turbolinks-Android. It appears that most HTML5 fields will work, but date/time and autofill will not.