--- !ruby/object:RI::MethodDescription 
aliases: []

block_params: 
comment: 
- !ruby/struct:SM::Flow::P 
  body: Extracts the singleton class, so that metaprogramming can be done on it.
- !ruby/struct:SM::Flow::P 
  body: "@return &lt;Class&gt; The meta class."
- !ruby/struct:SM::Flow::P 
  body: "@example [Setup]"
- !ruby/struct:SM::Flow::VERB 
  body: "  class MyString &lt; String; end\n\n  MyString.instance_eval do\n    define_method :foo do\n      puts self\n    end\n  end\n\n  MyString.meta_class.instance_eval do\n    define_method :bar do\n      puts self\n    end\n  end\n\n  def String.add_meta_var(var)\n    self.meta_class.instance_eval do\n      define_method var do\n        puts &quot;HELLO&quot;\n      end\n    end\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: "@example"
- !ruby/struct:SM::Flow::VERB 
  body: "  MyString.new(&quot;Hello&quot;).foo #=&gt; &quot;Hello&quot;\n"
- !ruby/struct:SM::Flow::P 
  body: "@example"
- !ruby/struct:SM::Flow::VERB 
  body: "  MyString.new(&quot;Hello&quot;).bar\n    #=&gt; NoMethodError: undefined method `bar' for &quot;Hello&quot;:MyString\n"
- !ruby/struct:SM::Flow::P 
  body: "@example"
- !ruby/struct:SM::Flow::VERB 
  body: "  MyString.foo\n    #=&gt; NoMethodError: undefined method `foo' for MyString:Class\n"
- !ruby/struct:SM::Flow::P 
  body: "@example"
- !ruby/struct:SM::Flow::VERB 
  body: "  MyString.bar\n    #=&gt; MyString\n"
- !ruby/struct:SM::Flow::P 
  body: "@example"
- !ruby/struct:SM::Flow::VERB 
  body: "  String.bar\n    #=&gt; NoMethodError: undefined method `bar' for String:Class\n"
- !ruby/struct:SM::Flow::P 
  body: "@example"
- !ruby/struct:SM::Flow::VERB 
  body: "  MyString.add_meta_var(:x)\n  MyString.x #=&gt; HELLO\n"
- !ruby/struct:SM::Flow::P 
  body: "@details [Description of Examples]"
- !ruby/struct:SM::Flow::VERB 
  body: "  As you can see, using #meta_class allows you to execute code (and here,\n  define a method) on the metaclass itself. It also allows you to define\n  class methods that can be run on subclasses, and then be able to execute\n  code on the metaclass of the subclass (here MyString).\n\n  In this case, we were able to define a class method (add_meta_var) on\n  String that was executable by the MyString subclass. It was then able to\n  define a method on the subclass by adding it to the MyString metaclass.\n\n  For more information, you can check out _why's excellent article at:\n  http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html\n"
full_name: Object#meta_class
is_singleton: false
name: meta_class
params: ()
visibility: public
