aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-03 05:09:02 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-03 05:09:02 +0000
commit7c89ca5431c370496e0f1ee3761781e6d74e57b4 (patch)
tree2751c199358dc2ccf70d6bc1f17211dc2795ee19 /lib
parent09fefc2e2047734a9162aac452cd2324a638b517 (diff)
downloadruby-7c89ca5431c370496e0f1ee3761781e6d74e57b4.tar.gz
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/ostruct.rb27
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index a95a0f1963..11eee24537 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -151,7 +151,7 @@ class OpenStruct
# 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
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
# 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
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
# 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
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
#
def ==(other)
return false unless other.kind_of?(OpenStruct)
- @table == other.table
+ @table == other.table!
end
#
@@ -312,7 +321,7 @@ class OpenStruct
#
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.