module Loom::CoreExt::ModuleExt
Public Instance Methods
loom_accessor(*names)
click to toggle source
A method like :attr_accessor, except the setter and getter methods are combined into one. It acts as a setter if an argument is passed, and always returns the currnet value.
# File lib/loom/core_ext.rb, line 21 def loom_accessor(*names) names.each do |name| instance_variable_set "@#{name}", nil define_method name do |*args| raise 'expected 0..1 arguments' if args.size > 1 instance_variable_set("@#{name}", args.first) if args.size > 0 instance_variable_get "@#{name}" end end end