Skip to content

Instantly share code, notes, and snippets.

@raizyr
Last active August 29, 2015 14:22
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 raizyr/bb15a7ea639daa09350b to your computer and use it in GitHub Desktop.
Save raizyr/bb15a7ea639daa09350b to your computer and use it in GitHub Desktop.
Not one line, but possibly easier to read
require 'test/unit'
include Test::Unit::Assertions
instance_true = {:source_dest_check => true}
instance_nil = {:source_dest_check => nil}
instance_false = {:source_dest_check => false}
instance_raise = {}
instance_garbage = {:source_dest_check => 'asdfl;kjag'}
def test(instance)
source_dest_check = !!instance[:source_dest_check] == instance[:source_dest_check] ? instance[:source_dest_check] : true
source_dest_check
end
assert test(instance_nil) == true, "Nil was not true"
assert test(instance_true) == true, "True was not true"
assert test(instance_false) == false, "False was not false"
assert test(instance_raise) == true, "Key error was not true"
assert test(instance_garbage) == true, "Garbage was not true"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment