Ruby on Rails interview questions – RoR test from PeopleCentric

One of the recruiting companies that I have collaborated with in the past decided to publish many of theirs IT tests . You can find, among others, a Ruby on Rails test. Enjoy 🙂

Why You Shouldn’t Use Float for Currency (floating point issues – explained for Ruby and RoR)

This article is a response to https://vladzloteanu.wordpress.com/2010/01/06/ruby-on-rails-interview-questions-update/

It is a VERY BAD IDEEA to use floating point arithmetics to deal with currency. In most of the programming languages. Basically, because you’ll end up loosing money :). And this (on the great majority of cases) is not desirable 🙂 .

I’ll show you some magic (that you may try at home):
~$ ruby --version
ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux]
~$ irb
irb(main):003:0> (10.12*100).to_i
=>; 1011

So, what just happened? Continue reading

Ruby on Rails Interview questions – update

Most of Google searches that hit my blog are about ‘ruby on rails interview questions‘.

Responding to this popular request 😉 , I will post 3 more questions that are related.

1. What type of data would you use to represent currency?

2. Why is it not a good practice to use float for currency?

3. Explain the following behaviour:

~$ ruby --version
ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux]
~$ irb
irb(main):003:0> (10.12*100).to_i
=>; 1011

The answer – in my next post .

Ruby on Rails interview questions – part 2

Continuing the “RoR interview questions” sequel(part one here) , these are some general Rails concepts and technologies questions. Enjoy :).

Continue reading

Ruby on Rails interview questions – Part one – Ruby

Ruby

This is the first article on the RoR interview questions. The purpose is not necessary to be used to ‘cheat’ on an interview, but to present some tricky things in Ruby and RoR.

Some (the majority) of the questions do not yet have answers. I will be filling the blanks.. soon 🙂

What is the duck typing?

The duck typing can be seen as one of the ruby implementation of polymorphism. The principle is: “If it walks like a duck and quacks like a duck, I would call it a duck.”. Below is an example of this principle (from http://www.javaworld.com/javaworld/jw-07-2006/jw-0717-ruby.html).

Continue reading