зеркало из https://github.com/github/ruby.git
[ruby/ostruct] Tweak doc
This commit is contained in:
Родитель
152ba86b6b
Коммит
bb2ba72c3b
|
@ -76,6 +76,10 @@
|
||||||
# Creating an open struct from a small Hash and accessing a few of the
|
# Creating an open struct from a small Hash and accessing a few of the
|
||||||
# entries can be 200 times slower than accessing the hash directly.
|
# entries can be 200 times slower than accessing the hash directly.
|
||||||
#
|
#
|
||||||
|
# This is a potential security issue; building OpenStruct from untrusted user data
|
||||||
|
# (e.g. JSON web request) may be susceptible to a "symbol denial of service" attack
|
||||||
|
# since the keys create methods and names of methods are never garbage collected.
|
||||||
|
#
|
||||||
# This may also be the source of incompatibilities between Ruby versions:
|
# This may also be the source of incompatibilities between Ruby versions:
|
||||||
#
|
#
|
||||||
# o = OpenStruct.new
|
# o = OpenStruct.new
|
||||||
|
@ -191,14 +195,14 @@ class OpenStruct
|
||||||
#
|
#
|
||||||
# Provides marshalling support for use by the Marshal library.
|
# Provides marshalling support for use by the Marshal library.
|
||||||
#
|
#
|
||||||
def marshal_dump
|
def marshal_dump # :nodoc:
|
||||||
@table
|
@table
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Provides marshalling support for use by the Marshal library.
|
# Provides marshalling support for use by the Marshal library.
|
||||||
#
|
#
|
||||||
def marshal_load(x)
|
def marshal_load(x) # :nodoc:
|
||||||
x.each_key{|key| new_ostruct_member!(key)}
|
x.each_key{|key| new_ostruct_member!(key)}
|
||||||
@table = x
|
@table = x
|
||||||
end
|
end
|
||||||
|
@ -253,7 +257,7 @@ class OpenStruct
|
||||||
# :call-seq:
|
# :call-seq:
|
||||||
# ostruct[name] -> object
|
# ostruct[name] -> object
|
||||||
#
|
#
|
||||||
# Returns the value of an attribute.
|
# Returns the value of an attribute, or `nil` if there is no such attribute.
|
||||||
#
|
#
|
||||||
# require "ostruct"
|
# require "ostruct"
|
||||||
# person = OpenStruct.new("name" => "John Smith", "age" => 70)
|
# person = OpenStruct.new("name" => "John Smith", "age" => 70)
|
||||||
|
@ -313,7 +317,7 @@ class OpenStruct
|
||||||
#
|
#
|
||||||
# person = OpenStruct.new(name: "John", age: 70, pension: 300)
|
# person = OpenStruct.new(name: "John", age: 70, pension: 300)
|
||||||
#
|
#
|
||||||
# person.delete_field("age") # => 70
|
# person.delete_field!("age") # => 70
|
||||||
# person # => #<OpenStruct name="John", pension=300>
|
# person # => #<OpenStruct name="John", pension=300>
|
||||||
#
|
#
|
||||||
# Setting the value to +nil+ will not remove the attribute:
|
# Setting the value to +nil+ will not remove the attribute:
|
||||||
|
@ -388,11 +392,7 @@ class OpenStruct
|
||||||
end
|
end
|
||||||
|
|
||||||
# Computes a hash code for this OpenStruct.
|
# Computes a hash code for this OpenStruct.
|
||||||
# Two OpenStruct objects with the same content will have the same hash code
|
def hash # :nodoc:
|
||||||
# (and will compare using #eql?).
|
|
||||||
#
|
|
||||||
# See also Object#hash.
|
|
||||||
def hash
|
|
||||||
@table.hash
|
@table.hash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче