@@ -439,25 +439,34 @@ def self.left_pad(spaces, text = '')
439
439
end
440
440
441
441
# Utility Method!
442
- # Given a class, output that same class, except preserve some backward compatible
443
- # or equivalent class names.
442
+ # Harmonize equivalent class names for comparison purposes.
444
443
# @param class_name [String] Class name as input
445
444
# @return [String] Class name as output
446
445
def self . class_name_for_diffy ( class_name )
447
- return 'Fixnum ' if class_name == 'Integer '
446
+ return 'Integer ' if class_name == 'Fixnum '
448
447
class_name
449
448
end
450
449
450
+ # Utility Method!
451
+ # `is_a?(class)` only allows one method, but this uses an array
452
+ # @param object [?] Object to consider
453
+ # @param classes [Array] Classes to determine if object is a member of
454
+ # @return [Boolean] True if object is_a any of the classes, false otherwise
455
+ def self . object_is_any_of? ( object , classes )
456
+ classes . each { |clazz | return true if object . is_a? clazz }
457
+ false
458
+ end
459
+
451
460
# Utility Method!
452
461
# Given an arbitrary object, convert it into a string for use by 'diffy'.
453
462
# This basically exists so we can do something prettier than just calling .inspect or .to_s
454
463
# on object types we anticipate seeing, while not failing entirely on other object types.
455
464
# @param obj [?] Object to be stringified
456
465
# @return [String] String representation of object for diffy
457
466
def self . stringify_for_diffy ( obj )
458
- return JSON . pretty_generate ( obj ) if [ Hash , Array ] . include? ( obj . class )
467
+ return JSON . pretty_generate ( obj ) if object_is_any_of? ( obj , [ Hash , Array ] )
459
468
return '""' if obj . is_a? ( String ) && obj == ''
460
- return obj if [ String , Fixnum , Integer , Float ] . include? ( obj . class )
469
+ return obj if object_is_any_of? ( obj , [ String , Fixnum , Integer , Float ] )
461
470
"#{ class_name_for_diffy ( obj . class ) } : #{ obj . inspect } "
462
471
end
463
472
0 commit comments