Title:Definice vlastního „makra“ attr_...
#!/usr/bin/env ruby # $Id: attr_list_accessor.rb,v 1.1 2005/10/04 08:52:07 radek Exp $ # $Source: /home/radek/cvs/ruby-book/example/attr_list_accessor.rb,v $ #- Copyright (C) 2003 Radek Hnilica class Class def attr_list_accessor (*symbols) symbols.each do |s| class_eval <<-EOS def add_#{s}(elem) (@#{s} ||= []) << elem end def each_#{s}(&block) (@#{s} ||= []).each(&block) end EOS end end end class Test attr_list_accessor :foo, :bar end