Slides
Next: More Objects >>

Classes as objects (advanced)

class Person

is syntactic sugar

same as

Person = Class.new

Note that Person is just a regular constant!

class Person
  def name
    "Alice"
  end
end

same as...

Person = Class.new
Person.class_eval do
  def name
    "Alice"
  end
end

the singleton class

aka "eigenclass" (but "metaclass" is incorrect)

method lookup

from http://blog.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html

method lookup goes through the eigenclass

method lookup

from http://blog.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html

comments powered by Disqus