Skip to content

Instantly share code, notes, and snippets.

@science
Created January 23, 2015 22:19
Show Gist options
  • Save science/5bcb169b5ce9aa132767 to your computer and use it in GitHub Desktop.
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
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