Skip to content

Instantly share code, notes, and snippets.

@eegrok
Created January 16, 2012 23:10
Show Gist options
  • Select an option

  • Save eegrok/1623513 to your computer and use it in GitHub Desktop.

Select an option

Save eegrok/1623513 to your computer and use it in GitHub Desktop.
singleton class / instance_methods stuff
class Blee
def self.classmeth
puts 'calling classmeth'
end
def instmeth
puts 'calling instmeth'
end
end
Blee.singleton_class.class_eval do
attr_accessor :class_level_attr_accessor
def anotherclassmeth
puts 'this is another class meth -- a more complicated way of doing the same as classmeth above'
end
end
puts Blee.object_id
puts Blee.singleton_class.object_id #different than object_id -- it's own class
puts Blee.class #Class
puts Blee.singleton_class.class #class
puts Blee.singleton_class.instance_methods #has classmeth, anotherclassmeth, books_published, books_published=, but not instmeth
puts Blee.singleton_class.instance_methods == Blee.methods #true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment