Fixed a bug in Ruby gem and added a test to cover it