The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Attr for Classes

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.
Attr for Classes Posted: Apr 25, 2005 11:53 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: Attr for Classes
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

Someone on Ruby-Talk was recently asking about an attr_accessor workalike for Classes. While writing my metaclasses article, I spent a bit of time poking around the goodies in Rails’ active_support directory and came across class_attribute_accessors.rb, which does the business.

After loading the class, use cattr_reader, cattr_writer, and cattr_accessor as you would the instance equivalents.

 class MailTruck
   cattr_accessor :trucks, :customers
 end
 MailTruck.trucks = [:UPS_TRUCK_9189, :UPS_TRUCK_9192]

You can also wield mattr_* methods as well.

Read: Attr for Classes

Topic: Chicago Ruby Meet Previous Topic   Next Topic Topic: The Infamous Hacker Who Took Down Localhost

Sponsored Links



Google
  Web Artima.com   

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