Skip to content

Instantly share code, notes, and snippets.

@noahgibbs
Created July 13, 2016 17:11
Show Gist options
  • Save noahgibbs/ee7119724046df529ff39da1c16bbb41 to your computer and use it in GitHub Desktop.
Save noahgibbs/ee7119724046df529ff39da1c16bbb41 to your computer and use it in GitHub Desktop.
class ParentClass
puts "Self when defining ParentClass: #{self.class} / #{self.inspect}"
def parent_method
puts "Self inside parent_method: #{self.class} / #{self.inspect}"
end
end
module MyModule
def self.module_obj_method
puts "Self inside module_obj_method: #{self.class} / #{self.inspect}"
end
def module_inst_method
puts "Self inside module_inst_method: #{self.class} / #{self.inspect}"
end
end
class AClass < ParentClass
include MyModule
def self.class_method
puts "Self inside AClass's class_method: #{self.class} / #{self.inspect}"
end
def instance_method
puts "Self inside AClass's instance_method: #{self.class} / #{self.inspect}"
end
end
AClass.class_method
MyModule.module_obj_method
a = AClass.new
a.instance_method
a.parent_method
a.module_inst_method
class << a
puts "Self while defining eigenclass: #{self.class} / #{self.inspect}"
def self.eigenclass_method
puts "Self inside eigenclass_method: #{self.class} / #{self.inspect}"
end
def eigenclass_instance_method
puts "Self inside eigenclass_instance_method: #{self.class} / #{self.inspect}"
end
end
puts "At-at variables:"
class ParentClass
@@var = "Parent class var"
end
class AClass
@@var = "Child class var"
end
class ParentClass
puts "Parentclass @@var: #{@@var.inspect}"
end
class AClass
puts "Child class @@var: #{@@var.inspect}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment