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