Skip to content

Instantly share code, notes, and snippets.

@wapcaplet
Created January 9, 2012 21:52
Show Gist options
  • Save wapcaplet/1585154 to your computer and use it in GitHub Desktop.
Save wapcaplet/1585154 to your computer and use it in GitHub Desktop.
# Return true if we're inside a conditional block, false otherwise.
#
def in_conditional?
return @conditional_stack.length > 1
end
# Return true if we're inside a true conditional block (one that
# evaluated true and should be executed).
#
def in_true_conditional?
return in_conditional? && @conditional_stack.last == true
end
# Return true if we're inside a false conditional block (one that
# evaluated false and should not be executed).
#
def in_false_conditional?
return in_conditional? && @conditional_stack.last == false
end
# Return true if we're inside a nil conditional block (one whose evaluation
# doesn't matter because it was precluded by an outer conditional block
# that was false)
#
def in_nil_conditional?
return in_conditional? && @conditional_stack.last == nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment