Method: LibGems::Specification.array_attribute

Defined in:
lib/libgems/specification.rb

.array_attribute(name) ⇒ Object

Same as :attribute, but ensures that values assigned to the attribute are array values by applying :to_a to the value.



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/libgems/specification.rb', line 175

def self.array_attribute(name)
  @@non_nil_attributes << ["@#{name}".intern, []]

  @@array_attributes << name
  @@attributes << [name, []]
  @@default_value[name] = []
  code = %{
    def #{name}
      @#{name} ||= []
    end
    def #{name}=(value)
      @#{name} = Array(value)
    end
  }

  module_eval code, __FILE__, __LINE__ - 9
end