Update:
You can get the class of an Object with .class
, and you can get a boolean response by using .class.is_a?(Class)
:
ary = []
ary.class => Array
hsh = {}
hsh.class => Hash
float = 10.456
float.class => Float
# and get boolean responses like this:
hsh.class.is_a?(Hash) => true
hsh.class.is_a?(Array) => false
So you can handle each Class
independently. If there are lots of potential classes, use a case
statement:
case value.class
when Array
# do something to the array
when Hash
# do something to the hash
when Float
# do something to the float
when Integer
# do something to the integer
...
end
Old:
You can use .include?()
array = ['a', 'b', 'c']
array.include?('c') => true
array.include?('d') => false
So for your example:
if array.include?(value)
# do something
else
# do something else
end