Sha256: 6cd9309dee622f63ccc1da5785b56d33da95e7e7c4c3bdb762fce283e7b6cb2d

Contents?: true

Size: 889 Bytes

Versions: 11

Compression:

Stored size: 889 Bytes

Contents

require_relative 'helper'


class TestUniversalAccessor < Test::Unit::TestCase

  class Accessor

    attr_accessor :val

    attr_reader :args

    def args=(*args)
      @args = args
    end

    universal_accessor :val, :args

  end# Accessor

  def accessor(*args)
    Accessor.new(*args)
  end

  def test_accessor()
    a = accessor
    assert_equal nil, a.val

    a.val 1
    assert_equal 1, a.val
    assert_equal 2, a.val(2)

    a.val = 3
    assert_equal 3, a.val
  end

  def test_accessor_splat_args()
    a = accessor

    a.args =   1, 2, 3;  assert_equal [[1, 2, 3]], a.args
    a.args =  [1, 2, 3]; assert_equal [[1, 2, 3]], a.args
    a.args = *[1, 2, 3]; assert_equal [[1, 2, 3]], a.args

    assert_equal  [1, 2, 3],  a.args(  1, 2, 3)
    assert_equal [[1, 2, 3]], a.args( [1, 2, 3])
    assert_equal  [1, 2, 3],  a.args(*[1, 2, 3])
  end

end# TestUniversalAccessor

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
xot-0.3 test/test_universal_accessor.rb
xot-0.2.1 test/test_universal_accessor.rb
xot-0.2 test/test_universal_accessor.rb
xot-0.1.42 test/test_universal_accessor.rb
xot-0.1.41 test/test_universal_accessor.rb
xot-0.1.40 test/test_universal_accessor.rb
xot-0.1.39 test/test_universal_accessor.rb
xot-0.1.38 test/test_universal_accessor.rb
xot-0.1.37 test/test_universal_accessor.rb
xot-0.1.36 test/test_universal_accessor.rb
xot-0.1.35 test/test_universal_accessor.rb