Created
August 29, 2016 13:02
-
-
Save javan/e9f5e552a50920cd6d436541944a5fde to your computer and use it in GitHub Desktop.
Kinda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "levenshtein" | |
class Object | |
def kinda?(klass) | |
Levenshtein.normalized_distance(self.class.to_s, klass.to_s) < 0.85 | |
end | |
end | |
>> "foo".class | |
=> String | |
>> "foo".is_a?(Struct) | |
=> false | |
>> "foo".kinda?(Struct) | |
=> true | |
>> "foo".kinda?(Fixnum) | |
=> false | |
>> 1.class | |
=> Fixnum | |
>> 1.is_a?(Float) | |
=> false | |
>> 1.kinda?(Float) | |
=> true | |
>> 1.kinda?(String) | |
=> false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment