ruby-changes:42482
From: ko1 <ko1@a...>
Date: Wed, 13 Apr 2016 11:07:05 +0900 (JST)
Subject: [ruby-changes:42482] ko1:r54556 (trunk): * test/ruby/test_basicinstructions.rb: add a test to check access
ko1 2016-04-13 12:03:37 +0900 (Wed, 13 Apr 2016) New Revision: 54556 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54556 Log: * test/ruby/test_basicinstructions.rb: add a test to check access instance variables on special const objects. All of such objects are frozen, so that we can not set instance variables for them. But we can read instance variables and return default value (nil). Modified files: trunk/ChangeLog trunk/test/ruby/test_basicinstructions.rb Index: test/ruby/test_basicinstructions.rb =================================================================== --- test/ruby/test_basicinstructions.rb (revision 54555) +++ test/ruby/test_basicinstructions.rb (revision 54556) @@ -698,4 +698,26 @@ class TestBasicInstructions < Test::Unit https://github.com/ruby/ruby/blob/trunk/test/ruby/test_basicinstructions.rb#L698 assert_equal [], [*a] assert_equal [1], [1, *a] end + + def test_special_const_instance_variables + assert_separately(%w(-W0), <<-INPUT, timeout: 60) + module M + def get + # we can not set instance variables on special const objects. + # However, we can access instance variables with default value (nil). + @ivar + end + end + class Fixnum; include M; end + class Float; include M; end + class Symbol; include M; end + class FalseClass; include M; end + class TrueClass; include M; end + class NilClass; include M; end + + [123, 1.2, :sym, false, true, nil].each{|obj| + assert_equal(nil, obj.get) + } + INPUT + end end Index: ChangeLog =================================================================== --- ChangeLog (revision 54555) +++ ChangeLog (revision 54556) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Apr 13 12:00:08 2016 Koichi Sasada <ko1@a...> + + * test/ruby/test_basicinstructions.rb: add a test to check access + instance variables on special const objects. + + All of such objects are frozen, so that we can not set instance + variables for them. But we can read instance variables and return + default value (nil). + Tue Apr 12 20:40:35 2016 Kaneko Yuichiro <spiketeika@g...> * ext/date/date_core.c (time_to_time): should preserve timezone -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/