Sha256: 36b59dca4793e000a4be91d476c69642d9c72584cb9558d46edb53f410e5ca52
Contents?: true
Size: 505 Bytes
Versions: 3
Compression:
Stored size: 505 Bytes
Contents
# adds ability to dynamically set instance vars & accessors module Attributable def create_method(name, &block) self.class.send(:define_method, name.to_sym, &block) end def create_setter(m) create_method("#{m}=".to_sym) { |v| instance_variable_set("@#{m}", v) } end def create_getter(m) create_method(m.to_sym) { instance_variable_get("@#{m}") } end def set_attr(method, value) create_setter(method) send "#{method}=".to_sym, value create_getter(method) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
arcrest-0.0.3 | lib/arcrest/attributable.rb |
arcrest-0.0.2 | lib/arcrest/attributable.rb |
arcrest-0.0.1 | lib/arcrest/attributable.rb |