module Rutema::SpecificationElement
This module adds functionality that allows us to arbitrarily add attributes to a class and then have the accessor methods for these attributes appear automagically.
It will also add a has_attribute? method to query if attribute is part of the object or not.
Public Instance Methods
attribute(symbol,value)
click to toggle source
adds an attribute to the class with the given __value__. __symbol__ can be a Symbol or a String, the rest are silently ignored
# File lib/rutema/core/objectmodel.rb, line 13 def attribute symbol,value @attributes||=Hash.new case symbol when String then @attributes[:"#{symbol}"]=value when Symbol then @attributes[symbol]=value end end
method_missing(symbol,*args)
click to toggle source
allows us to call object.attribute, object.attribute=, object.attribute? and object.has_attribute?
object.attribute and object.attribute? will throw NoMethodError if no attribute is set.
object.attribute= will set the attribute to the right operand and object.has_attribute? returns false or true according to the existence of the attribute.
Calls superclass method
# File lib/rutema/core/objectmodel.rb, line 26 def method_missing symbol,*args @attributes||=Hash.new key=symbol.id2name.chomp('?').chomp('=').sub(/^has_/,"") @attributes[:"#{key}"]=args[0] if key+"="==symbol.id2name if @attributes.has_key?(:"#{key}") return true if "has_"+key+"?"==symbol.id2name return @attributes[:"#{key}"] else return false if "has_"+key+"?"==symbol.id2name super(symbol,*args) end end
respond_to?(symbol,include_all)
click to toggle source
Calls superclass method
# File lib/rutema/core/objectmodel.rb, line 39 def respond_to? symbol,include_all @attributes||=Hash.new key=symbol.id2name.chomp('?').chomp('=').sub(/^has_/,"") if @attributes.has_key?(:"#{key}") return true else super(symbol,include_all) end end