Sha256: 03fe3a02d46039c2b7df5eb359a99f5460bb63c3313fda598b3956476631994b

Contents?: true

Size: 938 Bytes

Versions: 12

Compression:

Stored size: 938 Bytes

Contents

class Module
  module MultipleAttributes
    def attributes(*args)
      writable_flag = args.last
      if writable_flag != true && writable_flag != false
        writable_flag = false
      else
        args.pop
      end

      args.each do |arg|
        attr arg, writable_flag
      end
    end
  end

  include MultipleAttributes
end

module Module::MultipleAttributes::Etest
  class X
    attributes :a
    attributes :b, :c

    attributes :d, :e, true
  
    def initialize
      @a = "a"
      @b = "b"
      @c = "c"
      @d = "d"
      @e = "e"
    end
  end
  
  def test_ma
    x = X.new
    assert_equal %w(a b c d e), [ x.a, x.b, x.c, x.d, x.e ]

    assert_raise(NoMethodError) {
      x.a = 1
    }

    assert_raise(NoMethodError) {
      x.b = 1
    }

    assert_raise(NoMethodError) {
      x.c = 1
    }

    x.d = 1
    x.e = 2
    
    assert_equal 1, x.d
    assert_equal 2, x.e
  end
end if VEX_TEST == "base"

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
vex-0.6.2 lib/vex/base/object/multiple_attributes.rb
vex-0.4.4 lib/vex/base/object/multiple_attributes.rb
vex-0.4.2 lib/vex/base/object/multiple_attributes.rb
vex-0.3.3 lib/vex/base/object/multiple_attributes.rb
vex-0.2.9 lib/vex/base/object/multiple_attributes.rb
vex-0.2.8 lib/vex/base/object/multiple_attributes.rb
vex-0.2.7 lib/vex/base/object/multiple_attributes.rb
vex-0.2.6 lib/vex/base/object/multiple_attributes.rb
vex-0.2.5 lib/vex/base/object/multiple_attributes.rb
vex-0.2.2 lib/vex/base/object/multiple_attributes.rb
vex-0.2.1 lib/vex/base/object/multiple_attributes.rb
vex-0.2 lib/vex/base/object/multiple_attributes.rb