Skip to content

Instantly share code, notes, and snippets.

@ELLIOTTCABLE
Created October 2, 2008 04:37
Show Gist options
  • Save ELLIOTTCABLE/14276 to your computer and use it in GitHub Desktop.
Save ELLIOTTCABLE/14276 to your computer and use it in GitHub Desktop.
pure-code explanation of the Eigenclass
my_object = Object.new
another_object = Object.new
def my_object.a_method
self
end
my_object.a_method # => #<Object:0x33c0c>
another_object.a_method
# ~> -:9: undefined method `a_method' for #<Object:0x33bf8> (NoMethodError)
my_class = Class.new
another_class = Class.new
def my_class.a_method
self
end
my_class.a_method # => #<Class:0x33c20>
another_class.a_method
# ~> -:9: undefined method `a_method' for #<Class:0x33bf8> (NoMethodError)
class MyClass; end
class AnotherClass; end
class MyClass
def self.a_method
self
end
end
MyClass.a_method # => MyClass
AnotherClass.a_method
# ~> -:11: undefined method `a_method' for AnotherClass:Class (NoMethodError)
class Floobie; end
class Snapple; end
class Floobie
@@floobies = []
def self.all
@@floobies
end
def initialize name
@name = name
@@floobies << self
end
end
Floobie.new :one
Floobie.new :two
Floobie.new :three
Floobie.new :four
Floobie.all # => [#<Floobie:0x33644 @name=:one>, #<Floobie:0x335a4 @name=:two>, #<Floobie:0x33590 @name=:three>, #<Floobie:0x3357c @name=:four>]
Snapple.all
# ~> -:24: undefined method `all' for Snapple:Class (NoMethodError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment