Sha256: 4d1cf7c5f48ce9438ae9f7c062b9274857d99fee2042fc6664bb54c8d8842be3

Contents?: true

Size: 687 Bytes

Versions: 4

Compression:

Stored size: 687 Bytes

Contents

module SimplyUseful
  module HasAttributes
    def initialize(attributes = nil)
      self.attributes = attributes
      yield self if block_given?
    end

    def attributes=(attributes) # , guard_protected_attributes = true
                                #attributes = filter_attributes(attributes) if !attributes.blank? && guard_protected_attributes
      attributes.each do |key, value|
        send(key.to_s + '=', value)
      end if attributes
    end

    def attributes
      attributes = instance_variables
      attributes.delete("@errors")
      Hash[*attributes.collect { |attribute| [attribute[1..-1].to_sym, instance_variable_get(attribute)] }.flatten]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
simply_useful-0.2.3 lib/simply_useful/has_attributes.rb
simply_useful-0.2.2 lib/simply_useful/has_attributes.rb
simply_useful-0.2.1 lib/simply_useful/has_attributes.rb
simply_useful-0.2.0 lib/simply_useful/has_attributes.rb