Sha256: 2374c3c915cfe3f6a18d61e8781f5b4fecd2f1f17a127762db25b04289a9f14c

Contents?: true

Size: 401 Bytes

Versions: 26

Compression:

Stored size: 401 Bytes

Contents

class User
  class << self
    attr_reader :fields

    def field (*names)
      names.flatten.each do |name|
        attr_accessor name
        (@fields ||= []) << name
      end
    end
  end

  field :name
  field :age
  field :address
end

user = User.new
user.age     = 22
user.address = "1234"
user.name    = "Me"

#user.class.fields.each do |field|
#  puts user.send(field)
#end

puts user.name

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
procemon-0.4.2 test/prototype/class_field.rb
procemon-0.4.1 test/prototype/class_field.rb
procemon-0.4.0 test/prototype/class_field.rb
procemon-0.3.4 test/prototype/class_field.rb
procemon-0.3.3 test/prototype/class_field.rb
procemon-0.3.2 test/prototype/class_field.rb