Module: Attributable

Included in:
ArcREST::Layer
Defined in:
lib/arcrest/attributable.rb

Overview

adds ability to dynamically set instance vars & accessors

Instance Method Summary collapse

Instance Method Details

#create_getter(method) ⇒ Object



13
14
15
# File 'lib/arcrest/attributable.rb', line 13

def create_getter(method)
  create_method(method.to_sym) { instance_variable_get("@#{method}") }
end

#create_method(name, &block) ⇒ Object



5
6
7
# File 'lib/arcrest/attributable.rb', line 5

def create_method(name, &block)
  self.class.send(:define_method, name.to_sym, &block)
end

#create_setter(method) ⇒ Object



9
10
11
# File 'lib/arcrest/attributable.rb', line 9

def create_setter(method)
  create_method("#{method}=".to_sym) { |v| instance_variable_set("@#{method}", v) }
end

#set_attr(method, value) ⇒ Object



17
18
19
20
21
# File 'lib/arcrest/attributable.rb', line 17

def set_attr(method, value)
  create_setter(method)
  send "#{method}=".to_sym, value
  create_getter(method)
end