Created
January 23, 2015 22:19
-
-
Save science/5bcb169b5ce9aa132767 to your computer and use it in GitHub Desktop.
A very simple example of how to install a universal logger for all Objects, that responds differently depending on the Object class
This file contains 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
class Object | |
def self.ltlog(obj = self) | |
puts "class Hello" | |
if obj.class == Class then | |
puts obj.to_s | |
else | |
puts obj.class.to_s | |
end | |
if obj.kind_of?(String) then | |
puts "Special string object handling here" | |
end | |
end | |
def ltlog | |
puts "Hello" | |
self.class.ltlog(self) | |
end | |
end | |
Object.ltlog | |
# "class Hello" | |
# "Object" | |
"xyz".ltlog | |
# "Hello" | |
# "class Hello" | |
# "String" | |
# "Special string object handling here" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment