The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Seeing Metaclasses Clearly

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
Seeing Metaclasses Clearly Posted: Apr 18, 2005 12:46 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: Seeing Metaclasses Clearly
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

If you’re new to metaprogramming in Ruby and you’d like to start nursing a deep understanding for it, I’ve written a detailed article dissecting metaclasses. It’s all based on the following code, which I call Metaid.

 class Object
   # The hidden singleton lurks behind everyone
   def metaclass; class << self; self; end; end
   def meta_eval &blk; metaclass.instance_eval &blk; end

   # In class definitions, methods are added to the metaclass
   # of the class being defined.
   def meta_def name, &blk
     metaclass.instance_eval { define_method name, &blk }
   end

   # Just defines a class method
   def class_def name, &blk
     class_eval { define_method name, &blk }
   end
 end

The article contains a lot of stuff I excluded from chapter six of my cartoon Ruby book because it was just getting too specific for the common reader.

Read: Seeing Metaclasses Clearly

Topic: I own a Mac! Previous Topic   Next Topic Topic: I'm out

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use