Skip to content

Instantly share code, notes, and snippets.

@NateBarnes
Created November 5, 2013 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NateBarnes/7322941 to your computer and use it in GitHub Desktop.
Save NateBarnes/7322941 to your computer and use it in GitHub Desktop.
class Hash
alias :working_brackets :[]
def [] key
if rand(10) % 5 == 0
do_evil
else
working_brackets key
end
end
alias :working_fetch :fetch
def fetch *opts
if rand(10) % 3 == 0
do_evil
else
working_fetch *opts
end
end
def do_evil
working_fetch keys.sample
end
end
hsh = Hash.new
hsh[:one] = 1
hsh[:two] = 2
hsh[:three] = 3
hsh[:four] = 4
hsh[:five] = 5
10.times do
puts hsh[:one]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment