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

ruby-changes:41913

From: nobu <ko1@a...>
Date: Thu, 3 Mar 2016 14:09:05 +0900 (JST)
Subject: [ruby-changes:41913] nobu:r53987 (trunk): ostruct.rb: make internal methods private

nobu	2016-03-03 14:09:02 +0900 (Thu, 03 Mar 2016)

  New Revision: 53987

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

  Log:
    ostruct.rb: make internal methods private
    
    * lib/ostruct.rb (modifiable?, new_ostruct_member!, table!):
      rename methods for internal use with suffixes and make private,
      [ruby-core:71069] [Bug #11587]

  Modified files:
    trunk/ChangeLog
    trunk/lib/ostruct.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53986)
+++ ChangeLog	(revision 53987)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Mar  3 14:09:00 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/ostruct.rb (modifiable?, new_ostruct_member!, table!):
+	  rename methods for internal use with suffixes and make private,
+	  [ruby-core:71069] [Bug #11587]
+
 Wed Mar  2 16:28:48 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm_eval.c (method_missing): call by found method entry and get
Index: lib/ostruct.rb
===================================================================
--- lib/ostruct.rb	(revision 53986)
+++ lib/ostruct.rb	(revision 53987)
@@ -151,7 +151,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L151
   # 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? # :nodoc:
     begin
       @modifiable = true
     rescue
@@ -159,6 +159,10 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L159
     end
     @table
   end
+  private :modifiable?
+
+  # ::Kernel.warn("#{caller(1, 1)[0]}: do not use OpenStruct#modifiable")
+  alias modifiable modifiable? # :nodoc:
   protected :modifiable
 
   #
@@ -166,18 +170,22 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L170
   # 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) # :nodoc:
     name = name.to_sym
     unless singleton_class.method_defined?(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
+  private :new_ostruct_member!
+
+  # ::Kernel.warn("#{caller(1, 1)[0]}: do not use OpenStruct#new_ostruct_member")
+  alias new_ostruct_member new_ostruct_member! # :nodoc:
   protected :new_ostruct_member
 
   def freeze
-    @table.each_key {|key| new_ostruct_member(key)}
+    @table.each_key {|key| new_ostruct_member!(key)}
     super
   end
 
@@ -192,10 +200,10 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L200
       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
       if @table.key?(mid)
-        new_ostruct_member(mid) unless frozen?
+        new_ostruct_member!(mid) unless frozen?
         @table[mid]
       end
     else
@@ -222,7 +230,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L230
   #   person.age # => 42
   #
   def []=(name, value)
-    modifiable[new_ostruct_member(name)] = value
+    modifiable?[new_ostruct_member!(name)] = value
   end
 
   #
@@ -294,6 +302,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L302
 
   attr_reader :table # :nodoc:
   protected :table
+  alias table! table
 
   #
   # Compares this object and +other+ for equality.  An OpenStruct is equal to
@@ -302,7 +311,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L311
   #
   def ==(other)
     return false unless other.kind_of?(OpenStruct)
-    @table == other.table
+    @table == other.table!
   end
 
   #
@@ -312,7 +321,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L321
   #
   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.

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

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