-
-
Save cookrn/dc0a84786801b52457c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 = Hash.new | |
x.is_a?(Hash) | |
end | |
assert :array do | |
x = Array.new | |
x.is_a?(Array) | |
end | |
assert :is_a_fixnum do | |
x = 1 | |
x.is_a?(Integer) | |
end | |
assert :is_a_fixnum do | |
x = 2 | |
x.is_a?(Fixnum) | |
end | |
assert :is_a_numeric do | |
x = 3.0 | |
x.is_a?(Numeric) | |
end | |
assert :is_a_string do | |
x = 'a' | |
x.is_a?(String) | |
end | |
assert :is_a_symbol do | |
x = :wat | |
x.is_a?(Symbol) | |
end | |
assert :is_a_class do | |
x = Class.new | |
x.is_a?(Class) | |
end | |
assert :is_a_module do | |
x = Module.new | |
x.is_a?(Module) | |
end | |
assert :global_variable do | |
$x = 'wat' | |
defined?($x) == 'global-variable' | |
end | |
assert :local_variable do | |
x = 'wat' | |
defined?(x) == 'local-variable' | |
end | |
assert :instance_variable do | |
@x = 'wat' | |
defined?(@x) == 'instance-variable' | |
end | |
assert :constant do | |
X = 'wat' | |
defined?(X) == 'constant' | |
end | |
# bonus, again take less than 5 minutes | |
# | |
assert :explain_the_assert_method_below do | |
<<-___ | |
explain it here yo! | |
call the method with a name and a block. if the block returns something | |
truthy, then it "passes", else, it fails. | |
10.chr is the code for newline | |
to get the spot in the file that the assert block is, evaluate the constants | |
in the assert blocks scope(binding). | |
has to be passed a block because, if not, the file/line checking using | |
binding fails. | |
___ | |
end | |
assert :quine do | |
lines = nil | |
# lines = IO.readlines(__FILE__) # use another method to obtain lines | |
contents = File.read $0 | |
lines = contents.lines | |
end | |
BEGIN { | |
require 'yaml' | |
require 'map' | |
def assert(label, *args, &block) | |
file, line = eval('[__FILE__, __LINE__]', block.binding) | |
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 | |
if boolean | |
puts "#{ label } passed yo!" | |
else | |
warn "#{ label } barfed bitch!" | |
end | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jolly good show.
#110 is tricky. think it returns a string tho.