class Class
Public Instance Methods
attr_property(*accessors)
click to toggle source
Syntactic sugar for providing instance level attributes. Similar to attr_accessor
except the value of property is set without requiring “=” syntax, e.g.
foo.propname 5 (rather than <tt>foo.attrname=5</tt>) foo.propname #=> 5
In other words, setting is performed by specifing an argument, getting is performed using the same method call without an argument.
# File lib/core-extensions/class.rb, line 19 def attr_property(*accessors) accessors.each do |m| define_method(m) do |*val| instance_variable_set("@#{m}",val.first) unless val.empty? #Array Hack to avoid warning instance_variable_get("@#{m}") end end end