Skip to content

Instantly share code, notes, and snippets.

@abhinavmsra
abhinavmsra / money_best_practices.md
Last active November 12, 2023 13:00
Tips for Money Related Arithmetic in Ruby

Tips for Money Related Arithmetic in Ruby

  1. Never use float for performing arithmetic calculations relating to money.

    Floating numbers can sometimes show funky behaviour. It is not Ruby’s fault but the very implementation of floating numbers raises precision issues.

Examples of odd behaviour:

cd /etc/init.d
./ror_start_up.sh //filename may differ
@abhinavmsra
abhinavmsra / ruby_strings.rb
Last active September 11, 2015 08:31
Testing string operations in ruby
require 'benchmark'
iterations = 100_000
puts 'With Static Strings'
puts '======================================================'
Benchmark.bm do |bm|
bm.report('joining an array of strings') do
iterations.times do
['Testing', 'String', 'Operations', 'in', 'Ruby'].join(' ')