Sha256: e55fe1d81bce636a1c5932ab9b95dfd8f983aa211273ddab8a74db15440046fa
Contents?: true
Size: 915 Bytes
Versions: 13
Compression:
Stored size: 915 Bytes
Contents
# -*- coding: utf-8 -*- 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
13 entries across 13 versions & 1 rubygems