Skip to content

Instantly share code, notes, and snippets.

@ahoward
Last active August 29, 2015 14:01
Show Gist options
  • Save ahoward/fe9054410502dd8e233a to your computer and use it in GitHub Desktop.
Save ahoward/fe9054410502dd8e233a to your computer and use it in GitHub Desktop.
# make this script run, update your gist with the running script, and it's
# output in a separate gist. the entire quzi should take 1-3 minutes, but you
# get 5.
#
# the meat - take < 5 minutes to do this
#
assert :hash do
x = nil
x.is_a?(Hash)
end
assert :array do
x = nil
x.is_a?(Array)
end
assert :is_a_fixnum do
x = nil
x.is_a?(Integer)
end
assert :is_a_fixnum do
x = nil
x.is_a?(Fixnum)
end
assert :is_a_numeric do
x = nil
x.is_a?(Numeric)
end
assert :is_a_string do
x = nil
x.is_a?(String)
end
assert :is_a_symbol do
x = nil
x.is_a?(Symbol)
end
assert :is_a_class do
x = nil
x.is_a?(Class)
end
assert :is_a_module do
x = nil
x.is_a?(Module)
end
assert :global_variable do
defined?($x) == 'global-variable'
end
assert :local_variable do
defined?(x) == 'local-variable'
end
assert :instance_variable do
defined?(@x) == 'instance-variable'
end
assert :constant do
defined?(X) == 'constant'
end
# bonus, again take less than 5 minutes
#
assert :explain_the_assert_method_below do
<<-___
explain it here yo!
___
end
assert :quine do
lines = nil
lines = IO.readlines(__FILE__) # use another method to obtain lines
end
BEGIN {
require 'yaml'
require 'map'
def assert(label, *args, &block)
file, line = eval('[__FILE__, __LINE__]', block.binding) if block
boolean =
if block
begin
!!block.call
rescue Object => e
if ENV['DEBUG']
warn "#{ e.class }(#{ e.message })\n#{ Array(e.backtrace).join(10.chr) }"
end
false
end
else
args.empty? || args.all?
end
unless boolean
warn "#{ label } barfed bitch!"
end
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment