Skip to content

Is defining "dynamic" attributes possible? #192

@priverop

Description

@priverop

Hello, I'm considering using this gem but I don't know if this is possible to do:

class Person
  include ActiveAttr::Attributes

  attribute :first_name
  attribute :last_name
  # we retreive data from the database with ActiveRecord
  Languages.all.each do |lang| 
      attribute :"name_#{lang.name}", type: String
  end
end

person = Person.new
person.first_name = "Chris"
person.last_name = "Griego"
person.name_english = "Christian"
person.name_spanish = "Cristian"
person.attributes #=> {"first_name"=>"Chris", "last_name"=>"Griego", "name_english" => "Christian", "name_spanish" => "Cristian"}

I don't know if this is it: #6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions