Leam Hall
2016-07-26 12:36:47 UTC
I'm trying to use an object's class in a case statement. The tests work
in an "if" but I haven't figured out the case yet.
Suggestions?
Leam
######
my_string = "Hello there!"
puts "Found a String in if!" if my_string.class == String # This works
# This just gives "Not sure"
case my_string.class
when String
#when 'String' # This also fails
#when "String" # This also fails
puts "Found a string in case!"
else
puts "Not sure."
end
######
Unsubscribe: <mailto:ruby-talk-***@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
in an "if" but I haven't figured out the case yet.
Suggestions?
Leam
######
my_string = "Hello there!"
puts "Found a String in if!" if my_string.class == String # This works
# This just gives "Not sure"
case my_string.class
when String
#when 'String' # This also fails
#when "String" # This also fails
puts "Found a string in case!"
else
puts "Not sure."
end
######
Unsubscribe: <mailto:ruby-talk-***@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>