Module: SimpleJSONSchema::Concerns::HashAccessor

Included in:
Scope
Defined in:
lib/simple_json_schema/concerns/hash_acessor.rb

Instance Method Summary collapse

Instance Method Details

#hash_accessor(hash_name, accessors) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/simple_json_schema/concerns/hash_acessor.rb', line 6

def hash_accessor(hash_name, accessors)
  define_method(hash_name) do
    instance_variable_get("@#{hash_name}") ||
      instance_variable_set("@#{hash_name}", {})
  end

  accessors.each do |name|
    define_method(name) do
      instance_variable_get("@#{hash_name}")[name]
    end

    define_method("#{name}=") do |value|
      instance_variable_get("@#{hash_name}")[name] = value
    end
  end
end