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-2.0.0 test/prototype/class_field.rb
procemon-1.2.1 test/prototype/class_field.rb
procemon-1.2.0 test/prototype/class_field.rb
procemon-1.1.1 test/prototype/class_field.rb
procemon-1.0.4 test/prototype/class_field.rb
procemon-1.0.3 test/prototype/class_field.rb
procemon-1.0.1 test/prototype/class_field.rb
procemon-1.0.0 test/prototype/class_field.rb
procemon-0.9.1 test/prototype/class_field.rb
procemon-0.9.0 test/prototype/class_field.rb
procemon-0.8.1 test/prototype/class_field.rb
procemon-0.8.0 test/prototype/class_field.rb
procemon-0.7.0 test/prototype/class_field.rb
procemon-0.6.3 test/prototype/class_field.rb
procemon-0.6.2 test/prototype/class_field.rb
procemon-0.6.1 test/prototype/class_field.rb
procemon-0.5.0 test/prototype/class_field.rb
procemon-0.4.5 test/prototype/class_field.rb
procemon-0.4.4 test/prototype/class_field.rb
procemon-0.4.3 test/prototype/class_field.rb