I am trying to classify characters using a case statement, but I am not sure how I would go about this in Ruby.
Here is what I have:
case c
when ('a'..'z'), ('A'..'Z'), '$'
puts "#{c} true"
when ' '
#ignore spaces
else
puts "#{c} false"
end
But this is kind of messy and I’d like to simplify it. Is there anyway to simplify this with a regular expression?
Something like:
case c
when '[a-zA-Z$]'
puts "#{c} true"
when '[\s]'
#ignore whitespace
else
puts "#{c} false"
end
How would something like this be done in Ruby?
Absolutely! But the syntax should be like this: