[前][次][番号順一覧][スレッド一覧]

ruby-changes:32422

From: charliesome <ko1@a...>
Date: Sat, 4 Jan 2014 22:44:41 +0900 (JST)
Subject: [ruby-changes:32422] charliesome:r44501 (trunk): * struct.c (rb_struct_set): return assigned value from setter method

charliesome	2014-01-04 22:44:34 +0900 (Sat, 04 Jan 2014)

  New Revision: 44501

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44501

  Log:
    * struct.c (rb_struct_set): return assigned value from setter method
      rather than struct object. [Bug #9353] [ruby-core:59509]
    
    * test/ruby/test_struct.rb (test_setter_method_returns_value): add test

  Modified files:
    trunk/ChangeLog
    trunk/struct.c
    trunk/test/ruby/test_struct.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44500)
+++ ChangeLog	(revision 44501)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jan  4 22:44:00 2014  Charlie Somerville  <charliesome@r...>
+
+	* struct.c (rb_struct_set): return assigned value from setter method
+	  rather than struct object. [Bug #9353] [ruby-core:59509]
+
+	* test/ruby/test_struct.rb (test_setter_method_returns_value): add test
+
 Sat Jan  4 21:44:31 2014  Kazuhiro NISHIYAMA  <zn@m...>
 
 	* test/ruby/test_gc.rb (TestGc#test_latest_gc_info): use
Index: struct.c
===================================================================
--- struct.c	(revision 44500)
+++ struct.c	(revision 44501)
@@ -156,7 +156,8 @@ rb_struct_set(VALUE obj, VALUE val) https://github.com/ruby/ruby/blob/trunk/struct.c#L156
     for (i=0; i<len; i++) {
 	slot = RARRAY_AREF(members, i);
 	if (rb_id_attrset(SYM2ID(slot)) == rb_frame_this_func()) {
-	    return RSTRUCT_SET(obj, i, val);
+	    RSTRUCT_SET(obj, i, val);
+	    return val;
 	}
     }
     rb_name_error(rb_frame_this_func(), "`%s' is not a struct member",
Index: test/ruby/test_struct.rb
===================================================================
--- test/ruby/test_struct.rb	(revision 44500)
+++ test/ruby/test_struct.rb	(revision 44501)
@@ -298,6 +298,12 @@ module TestStruct https://github.com/ruby/ruby/blob/trunk/test/ruby/test_struct.rb#L298
     assert_same(x, o.b!)
   end
 
+  def test_setter_method_returns_value
+    klass = @Struct.new(:a)
+    x = klass.new
+    assert_equal "[Bug #9353]", x.send(:a=, "[Bug #9353]")
+  end
+
   class TopStruct < Test::Unit::TestCase
     include TestStruct
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]