module Rubyfocus::IDRef::ClassMethods
Public Instance Methods
idref(*names)
click to toggle source
# File lib/rubyfocus/includes/idref.rb, line 4 def idref *names names.each do |name| name_id = "#{name}_id".to_sym attr_accessor name_id define_method(name) do return document && (id_value = send(name_id)) && document.find(id_value) end define_method("#{name}=") do |o| if o.nil? self.send("#{name}_id=", nil) elsif o.respond_to?(:id) self.send("#{name}_id=", o.id) else raise ArgumentError, "#{self.class}##{name}= called with argument #{o}, which does not respond to :id." end end end end