Skip to content

Instantly share code, notes, and snippets.

View jmartelletti's full-sized avatar

James Martelletti jmartelletti

  • Melbourne, Australia
View GitHub Profile
@jmartelletti
jmartelletti / gist:93795edac1d7e4c8f764
Created September 17, 2014 09:46
Ruby silently evaluating to the wrong value?
ERROR = "error"
STOPPED = "stopped"
RUNNING = "running"
state = ERROR
desired = STOPPED
([RUNNING].include? state) || (state == ERROR && desired == STOPPED)
[RUNNING].include?(state) || (state == ERROR && desired == STOPPED)
[RUNNING].include? state || (state == ERROR && desired == STOPPED)
require "binding_of_caller"
calls = []
stats = {}
trace = TracePoint.new(:call, :class, :return) do |tp|
next if tp.path =~ /\/var\/lib\/gems\/2\.0\.0/
next if tp.path =~ /\/usr\/lib\/ruby\/2\.0\.0/
next if tp.path =~ /\(erb\)/
stats[tp.defined_class] ||= {}
scans = [
['A','B','C','D','A','B','A','A'],
['C','C','C','C','C','C','C'],
['A','B','C','D']
]
products = [
{ :code => 'A', :volume => 4, :price => 7 },
{ :code => 'A', :volume => 1, :price => 2 },
{ :code => 'B', :volume => 1, :price => 12 },