ruby typeof
# Define a method to determine the type of an object
def ruby_typeof(obj)
# Check if the object is nil
if obj.nil?
return 'NilClass' # Return 'NilClass' if the object is nil
else
return obj.class.to_s # Return the class name of the object as a string
end
end
# Example usage:
puts ruby_typeof(5) # Outputs 'Integer'
puts ruby_typeof("Hello") # Outputs 'String'
puts ruby_typeof(nil) # Outputs 'NilClass'
puts ruby_typeof([1, 2, 3]) # Outputs 'Array'