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

ruby-changes:37100

From: nobu <ko1@a...>
Date: Thu, 8 Jan 2015 16:08:24 +0900 (JST)
Subject: [ruby-changes:37100] nobu:r49181 (trunk): Revert GH-808

nobu	2015-01-08 16:07:59 +0900 (Thu, 08 Jan 2015)

  New Revision: 49181

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

  Log:
    Revert GH-808

  Modified files:
    trunk/ChangeLog
    trunk/lib/ostruct.rb
    trunk/test/ostruct/test_ostruct.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49180)
+++ ChangeLog	(revision 49181)
@@ -56,12 +56,6 @@ Mon Jan  5 14:58:01 2015  SHIBATA Hirosh https://github.com/ruby/ruby/blob/trunk/ChangeLog#L56
 	* test/ruby/test_io.rb: added timeout for AIX environment.
 	  [ruby-core:62983][Bug #9917]
 
-Mon Jan  5 10:57:24 2015  Nobuyoshi Nakada  <nobu@r...>
-
-	* lib/ostruct.rb (modifiable?, new_ostruct_member!, table!):
-	  append suffixes to protected methods so that they will not clash
-	  with assigned members.  [Fix GH-806]
-
 Sun Jan  4 22:33:33 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* test/lib/test/unit.rb (ExcludesOption): add "excludes" support
Index: lib/ostruct.rb
===================================================================
--- lib/ostruct.rb	(revision 49180)
+++ lib/ostruct.rb	(revision 49181)
@@ -90,7 +90,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L90
       hash.each_pair do |k, v|
         k = k.to_sym
         @table[k] = v
-        new_ostruct_member!(k)
+        new_ostruct_member(k)
       end
     end
   end
@@ -99,7 +99,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L99
   def initialize_copy(orig)
     super
     @table = @table.dup
-    @table.each_key{|key| new_ostruct_member!(key)}
+    @table.each_key{|key| new_ostruct_member(key)}
   end
 
   #
@@ -141,14 +141,14 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L141
   #
   def marshal_load(x)
     @table = x
-    @table.each_key{|key| new_ostruct_member!(key)}
+    @table.each_key{|key| new_ostruct_member(key)}
   end
 
   #
   # Used internally to check if the OpenStruct is able to be
   # modified before granting access to the internal Hash table to be modified.
   #
-  def modifiable?
+  def modifiable
     begin
       @modifiable = true
     rescue
@@ -156,22 +156,22 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L156
     end
     @table
   end
-  protected :modifiable?
+  protected :modifiable
 
   #
   # Used internally to defined properties on the
   # OpenStruct. It does this by using the metaprogramming function
   # define_singleton_method for both the getter method and the setter method.
   #
-  def new_ostruct_member!(name)
+  def new_ostruct_member(name)
     name = name.to_sym
     unless respond_to?(name)
       define_singleton_method(name) { @table[name] }
-      define_singleton_method("#{name}=") { |x| modifiable?[name] = x }
+      define_singleton_method("#{name}=") { |x| modifiable[name] = x }
     end
     name
   end
-  protected :new_ostruct_member!
+  protected :new_ostruct_member
 
   def method_missing(mid, *args) # :nodoc:
     mname = mid.id2name
@@ -180,7 +180,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L180
       if len != 1
         raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
       end
-      modifiable?[new_ostruct_member!(mname)] = args[0]
+      modifiable[new_ostruct_member(mname)] = args[0]
     elsif len == 0
       @table[mid]
     else
@@ -207,7 +207,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L207
   #   person.age # => 42
   #
   def []=(name, value)
-    modifiable?[new_ostruct_member!(name)] = value
+    modifiable[new_ostruct_member(name)] = value
   end
 
   #
@@ -256,7 +256,6 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L256
 
   attr_reader :table # :nodoc:
   protected :table
-  alias table! table
 
   #
   # Compares this object and +other+ for equality.  An OpenStruct is equal to
@@ -265,7 +264,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L264
   #
   def ==(other)
     return false unless other.kind_of?(OpenStruct)
-    @table == other.table!
+    @table == other.table
   end
 
   #
@@ -275,7 +274,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L274
   #
   def eql?(other)
     return false unless other.kind_of?(OpenStruct)
-    @table.eql?(other.table!)
+    @table.eql?(other.table)
   end
 
   # Compute a hash-code for this OpenStruct.
Index: test/ostruct/test_ostruct.rb
===================================================================
--- test/ostruct/test_ostruct.rb	(revision 49180)
+++ test/ostruct/test_ostruct.rb	(revision 49181)
@@ -135,10 +135,4 @@ class TC_OpenStruct < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ostruct/test_ostruct.rb#L135
     e = assert_raise(ArgumentError) { os.send :foo=, true, true }
     assert_match(/#{__callee__}/, e.backtrace[0])
   end
-
-  def test_modifiable
-    os = OpenStruct.new(modifiable: true)
-    assert_equal true, os.modifiable
-    assert_nothing_raised { os.foo = true }
-  end
 end

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

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