Skip to content

Instantly share code, notes, and snippets.

@haveanicedavid
Created May 26, 2015 22:07
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 haveanicedavid/a33feb1feb81d3b1b2c8 to your computer and use it in GitHub Desktop.
Save haveanicedavid/a33feb1feb81d3b1b2c8 to your computer and use it in GitHub Desktop.
woooo
class WFString
REFLECTION = { "{" => "}", "(" => ")", "[" => "]"}
def self.check(string)
first_in = []
surround_string = string.gsub(/[^\[\]\{\}\(\)]/, "")
return false if surround_string.length % 2 != 0
surround_string.chars.each do |symbol|
if REFLECTION[symbol]
first_in << symbol
else
return false unless REFLECTION[first_in.last] == symbol
first_in.pop
end
end
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment