Method: ClassX::Attributes#attribute_of
- Defined in:
- lib/classx/attributes.rb
#attribute_of ⇒ Object
return Hash of attribute’s name as a key and attribute’s meta class as a value. for example,
class YourClass
include ClassX
has :x
end
YourClass.attribute_of #=> { "x" => <ClassX::Attribute: ... > }
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/classx/attributes.rb', line 34 def attribute_of unless instance_variable_defined?('@__attribute_of') && @__attribute_of @__attribute_of = {} private_instance_methods.select {|meth| meth.to_s =~ ATTRIBUTE_REGEX }.each do |meth| key = meth.to_s.sub(ATTRIBUTE_REGEX) { $1 } @__attribute_of[key] = __send__ "attribute_of:#{key}" end end @__attribute_of end |