Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/ruby32/share/ruby
File: ostruct.rb
# frozen_string_literal: true
[0] Fix | Delete
#
[1] Fix | Delete
# = ostruct.rb: OpenStruct implementation
[2] Fix | Delete
#
[3] Fix | Delete
# Author:: Yukihiro Matsumoto
[4] Fix | Delete
# Documentation:: Gavin Sinclair
[5] Fix | Delete
#
[6] Fix | Delete
# OpenStruct allows the creation of data objects with arbitrary attributes.
[7] Fix | Delete
# See OpenStruct for an example.
[8] Fix | Delete
#
[9] Fix | Delete
[10] Fix | Delete
#
[11] Fix | Delete
# An OpenStruct is a data structure, similar to a Hash, that allows the
[12] Fix | Delete
# definition of arbitrary attributes with their accompanying values. This is
[13] Fix | Delete
# accomplished by using Ruby's metaprogramming to define methods on the class
[14] Fix | Delete
# itself.
[15] Fix | Delete
#
[16] Fix | Delete
# == Examples
[17] Fix | Delete
#
[18] Fix | Delete
# require "ostruct"
[19] Fix | Delete
#
[20] Fix | Delete
# person = OpenStruct.new
[21] Fix | Delete
# person.name = "John Smith"
[22] Fix | Delete
# person.age = 70
[23] Fix | Delete
#
[24] Fix | Delete
# person.name # => "John Smith"
[25] Fix | Delete
# person.age # => 70
[26] Fix | Delete
# person.address # => nil
[27] Fix | Delete
#
[28] Fix | Delete
# An OpenStruct employs a Hash internally to store the attributes and values
[29] Fix | Delete
# and can even be initialized with one:
[30] Fix | Delete
#
[31] Fix | Delete
# australia = OpenStruct.new(:country => "Australia", :capital => "Canberra")
[32] Fix | Delete
# # => #<OpenStruct country="Australia", capital="Canberra">
[33] Fix | Delete
#
[34] Fix | Delete
# Hash keys with spaces or characters that could normally not be used for
[35] Fix | Delete
# method calls (e.g. <code>()[]*</code>) will not be immediately available
[36] Fix | Delete
# on the OpenStruct object as a method for retrieval or assignment, but can
[37] Fix | Delete
# still be reached through the Object#send method or using [].
[38] Fix | Delete
#
[39] Fix | Delete
# measurements = OpenStruct.new("length (in inches)" => 24)
[40] Fix | Delete
# measurements[:"length (in inches)"] # => 24
[41] Fix | Delete
# measurements.send("length (in inches)") # => 24
[42] Fix | Delete
#
[43] Fix | Delete
# message = OpenStruct.new(:queued? => true)
[44] Fix | Delete
# message.queued? # => true
[45] Fix | Delete
# message.send("queued?=", false)
[46] Fix | Delete
# message.queued? # => false
[47] Fix | Delete
#
[48] Fix | Delete
# Removing the presence of an attribute requires the execution of the
[49] Fix | Delete
# delete_field method as setting the property value to +nil+ will not
[50] Fix | Delete
# remove the attribute.
[51] Fix | Delete
#
[52] Fix | Delete
# first_pet = OpenStruct.new(:name => "Rowdy", :owner => "John Smith")
[53] Fix | Delete
# second_pet = OpenStruct.new(:name => "Rowdy")
[54] Fix | Delete
#
[55] Fix | Delete
# first_pet.owner = nil
[56] Fix | Delete
# first_pet # => #<OpenStruct name="Rowdy", owner=nil>
[57] Fix | Delete
# first_pet == second_pet # => false
[58] Fix | Delete
#
[59] Fix | Delete
# first_pet.delete_field(:owner)
[60] Fix | Delete
# first_pet # => #<OpenStruct name="Rowdy">
[61] Fix | Delete
# first_pet == second_pet # => true
[62] Fix | Delete
#
[63] Fix | Delete
# Ractor compatibility: A frozen OpenStruct with shareable values is itself shareable.
[64] Fix | Delete
#
[65] Fix | Delete
# == Caveats
[66] Fix | Delete
#
[67] Fix | Delete
# An OpenStruct utilizes Ruby's method lookup structure to find and define the
[68] Fix | Delete
# necessary methods for properties. This is accomplished through the methods
[69] Fix | Delete
# method_missing and define_singleton_method.
[70] Fix | Delete
#
[71] Fix | Delete
# This should be a consideration if there is a concern about the performance of
[72] Fix | Delete
# the objects that are created, as there is much more overhead in the setting
[73] Fix | Delete
# of these properties compared to using a Hash or a Struct.
[74] Fix | Delete
# Creating an open struct from a small Hash and accessing a few of the
[75] Fix | Delete
# entries can be 200 times slower than accessing the hash directly.
[76] Fix | Delete
#
[77] Fix | Delete
# This is a potential security issue; building OpenStruct from untrusted user data
[78] Fix | Delete
# (e.g. JSON web request) may be susceptible to a "symbol denial of service" attack
[79] Fix | Delete
# since the keys create methods and names of methods are never garbage collected.
[80] Fix | Delete
#
[81] Fix | Delete
# This may also be the source of incompatibilities between Ruby versions:
[82] Fix | Delete
#
[83] Fix | Delete
# o = OpenStruct.new
[84] Fix | Delete
# o.then # => nil in Ruby < 2.6, enumerator for Ruby >= 2.6
[85] Fix | Delete
#
[86] Fix | Delete
# Builtin methods may be overwritten this way, which may be a source of bugs
[87] Fix | Delete
# or security issues:
[88] Fix | Delete
#
[89] Fix | Delete
# o = OpenStruct.new
[90] Fix | Delete
# o.methods # => [:to_h, :marshal_load, :marshal_dump, :each_pair, ...
[91] Fix | Delete
# o.methods = [:foo, :bar]
[92] Fix | Delete
# o.methods # => [:foo, :bar]
[93] Fix | Delete
#
[94] Fix | Delete
# To help remedy clashes, OpenStruct uses only protected/private methods ending with <code>!</code>
[95] Fix | Delete
# and defines aliases for builtin public methods by adding a <code>!</code>:
[96] Fix | Delete
#
[97] Fix | Delete
# o = OpenStruct.new(make: 'Bentley', class: :luxury)
[98] Fix | Delete
# o.class # => :luxury
[99] Fix | Delete
# o.class! # => OpenStruct
[100] Fix | Delete
#
[101] Fix | Delete
# It is recommended (but not enforced) to not use fields ending in <code>!</code>;
[102] Fix | Delete
# Note that a subclass' methods may not be overwritten, nor can OpenStruct's own methods
[103] Fix | Delete
# ending with <code>!</code>.
[104] Fix | Delete
#
[105] Fix | Delete
# For all these reasons, consider not using OpenStruct at all.
[106] Fix | Delete
#
[107] Fix | Delete
class OpenStruct
[108] Fix | Delete
VERSION = "0.5.5"
[109] Fix | Delete
[110] Fix | Delete
#
[111] Fix | Delete
# Creates a new OpenStruct object. By default, the resulting OpenStruct
[112] Fix | Delete
# object will have no attributes.
[113] Fix | Delete
#
[114] Fix | Delete
# The optional +hash+, if given, will generate attributes and values
[115] Fix | Delete
# (can be a Hash, an OpenStruct or a Struct).
[116] Fix | Delete
# For example:
[117] Fix | Delete
#
[118] Fix | Delete
# require "ostruct"
[119] Fix | Delete
# hash = { "country" => "Australia", :capital => "Canberra" }
[120] Fix | Delete
# data = OpenStruct.new(hash)
[121] Fix | Delete
#
[122] Fix | Delete
# data # => #<OpenStruct country="Australia", capital="Canberra">
[123] Fix | Delete
#
[124] Fix | Delete
def initialize(hash=nil)
[125] Fix | Delete
if hash
[126] Fix | Delete
update_to_values!(hash)
[127] Fix | Delete
else
[128] Fix | Delete
@table = {}
[129] Fix | Delete
end
[130] Fix | Delete
end
[131] Fix | Delete
[132] Fix | Delete
# Duplicates an OpenStruct object's Hash table.
[133] Fix | Delete
private def initialize_clone(orig) # :nodoc:
[134] Fix | Delete
super # clones the singleton class for us
[135] Fix | Delete
@table = @table.dup unless @table.frozen?
[136] Fix | Delete
end
[137] Fix | Delete
[138] Fix | Delete
private def initialize_dup(orig) # :nodoc:
[139] Fix | Delete
super
[140] Fix | Delete
update_to_values!(@table)
[141] Fix | Delete
end
[142] Fix | Delete
[143] Fix | Delete
private def update_to_values!(hash) # :nodoc:
[144] Fix | Delete
@table = {}
[145] Fix | Delete
hash.each_pair do |k, v|
[146] Fix | Delete
set_ostruct_member_value!(k, v)
[147] Fix | Delete
end
[148] Fix | Delete
end
[149] Fix | Delete
[150] Fix | Delete
#
[151] Fix | Delete
# call-seq:
[152] Fix | Delete
# ostruct.to_h -> hash
[153] Fix | Delete
# ostruct.to_h {|name, value| block } -> hash
[154] Fix | Delete
#
[155] Fix | Delete
# Converts the OpenStruct to a hash with keys representing
[156] Fix | Delete
# each attribute (as symbols) and their corresponding values.
[157] Fix | Delete
#
[158] Fix | Delete
# If a block is given, the results of the block on each pair of
[159] Fix | Delete
# the receiver will be used as pairs.
[160] Fix | Delete
#
[161] Fix | Delete
# require "ostruct"
[162] Fix | Delete
# data = OpenStruct.new("country" => "Australia", :capital => "Canberra")
[163] Fix | Delete
# data.to_h # => {:country => "Australia", :capital => "Canberra" }
[164] Fix | Delete
# data.to_h {|name, value| [name.to_s, value.upcase] }
[165] Fix | Delete
# # => {"country" => "AUSTRALIA", "capital" => "CANBERRA" }
[166] Fix | Delete
#
[167] Fix | Delete
if {test: :to_h}.to_h{ [:works, true] }[:works] # RUBY_VERSION < 2.6 compatibility
[168] Fix | Delete
def to_h(&block)
[169] Fix | Delete
if block
[170] Fix | Delete
@table.to_h(&block)
[171] Fix | Delete
else
[172] Fix | Delete
@table.dup
[173] Fix | Delete
end
[174] Fix | Delete
end
[175] Fix | Delete
else
[176] Fix | Delete
def to_h(&block)
[177] Fix | Delete
if block
[178] Fix | Delete
@table.map(&block).to_h
[179] Fix | Delete
else
[180] Fix | Delete
@table.dup
[181] Fix | Delete
end
[182] Fix | Delete
end
[183] Fix | Delete
end
[184] Fix | Delete
[185] Fix | Delete
#
[186] Fix | Delete
# :call-seq:
[187] Fix | Delete
# ostruct.each_pair {|name, value| block } -> ostruct
[188] Fix | Delete
# ostruct.each_pair -> Enumerator
[189] Fix | Delete
#
[190] Fix | Delete
# Yields all attributes (as symbols) along with the corresponding values
[191] Fix | Delete
# or returns an enumerator if no block is given.
[192] Fix | Delete
#
[193] Fix | Delete
# require "ostruct"
[194] Fix | Delete
# data = OpenStruct.new("country" => "Australia", :capital => "Canberra")
[195] Fix | Delete
# data.each_pair.to_a # => [[:country, "Australia"], [:capital, "Canberra"]]
[196] Fix | Delete
#
[197] Fix | Delete
def each_pair
[198] Fix | Delete
return to_enum(__method__) { @table.size } unless defined?(yield)
[199] Fix | Delete
@table.each_pair{|p| yield p}
[200] Fix | Delete
self
[201] Fix | Delete
end
[202] Fix | Delete
[203] Fix | Delete
#
[204] Fix | Delete
# Provides marshalling support for use by the Marshal library.
[205] Fix | Delete
#
[206] Fix | Delete
def marshal_dump # :nodoc:
[207] Fix | Delete
@table
[208] Fix | Delete
end
[209] Fix | Delete
[210] Fix | Delete
#
[211] Fix | Delete
# Provides marshalling support for use by the Marshal library.
[212] Fix | Delete
#
[213] Fix | Delete
alias_method :marshal_load, :update_to_values! # :nodoc:
[214] Fix | Delete
[215] Fix | Delete
#
[216] Fix | Delete
# Used internally to defined properties on the
[217] Fix | Delete
# OpenStruct. It does this by using the metaprogramming function
[218] Fix | Delete
# define_singleton_method for both the getter method and the setter method.
[219] Fix | Delete
#
[220] Fix | Delete
def new_ostruct_member!(name) # :nodoc:
[221] Fix | Delete
unless @table.key?(name) || is_method_protected!(name)
[222] Fix | Delete
if defined?(::Ractor)
[223] Fix | Delete
getter_proc = nil.instance_eval{ Proc.new { @table[name] } }
[224] Fix | Delete
setter_proc = nil.instance_eval{ Proc.new {|x| @table[name] = x} }
[225] Fix | Delete
::Ractor.make_shareable(getter_proc)
[226] Fix | Delete
::Ractor.make_shareable(setter_proc)
[227] Fix | Delete
else
[228] Fix | Delete
getter_proc = Proc.new { @table[name] }
[229] Fix | Delete
setter_proc = Proc.new {|x| @table[name] = x}
[230] Fix | Delete
end
[231] Fix | Delete
define_singleton_method!(name, &getter_proc)
[232] Fix | Delete
define_singleton_method!("#{name}=", &setter_proc)
[233] Fix | Delete
end
[234] Fix | Delete
end
[235] Fix | Delete
private :new_ostruct_member!
[236] Fix | Delete
[237] Fix | Delete
private def is_method_protected!(name) # :nodoc:
[238] Fix | Delete
if !respond_to?(name, true)
[239] Fix | Delete
false
[240] Fix | Delete
elsif name.match?(/!$/)
[241] Fix | Delete
true
[242] Fix | Delete
else
[243] Fix | Delete
owner = method!(name).owner
[244] Fix | Delete
if owner.class == ::Class
[245] Fix | Delete
owner < ::OpenStruct
[246] Fix | Delete
else
[247] Fix | Delete
self.class!.ancestors.any? do |mod|
[248] Fix | Delete
return false if mod == ::OpenStruct
[249] Fix | Delete
mod == owner
[250] Fix | Delete
end
[251] Fix | Delete
end
[252] Fix | Delete
end
[253] Fix | Delete
end
[254] Fix | Delete
[255] Fix | Delete
def freeze
[256] Fix | Delete
@table.freeze
[257] Fix | Delete
super
[258] Fix | Delete
end
[259] Fix | Delete
[260] Fix | Delete
private def method_missing(mid, *args) # :nodoc:
[261] Fix | Delete
len = args.length
[262] Fix | Delete
if mname = mid[/.*(?==\z)/m]
[263] Fix | Delete
if len != 1
[264] Fix | Delete
raise! ArgumentError, "wrong number of arguments (given #{len}, expected 1)", caller(1)
[265] Fix | Delete
end
[266] Fix | Delete
set_ostruct_member_value!(mname, args[0])
[267] Fix | Delete
elsif len == 0
[268] Fix | Delete
@table[mid]
[269] Fix | Delete
else
[270] Fix | Delete
begin
[271] Fix | Delete
super
[272] Fix | Delete
rescue NoMethodError => err
[273] Fix | Delete
err.backtrace.shift
[274] Fix | Delete
raise!
[275] Fix | Delete
end
[276] Fix | Delete
end
[277] Fix | Delete
end
[278] Fix | Delete
[279] Fix | Delete
#
[280] Fix | Delete
# :call-seq:
[281] Fix | Delete
# ostruct[name] -> object
[282] Fix | Delete
#
[283] Fix | Delete
# Returns the value of an attribute, or +nil+ if there is no such attribute.
[284] Fix | Delete
#
[285] Fix | Delete
# require "ostruct"
[286] Fix | Delete
# person = OpenStruct.new("name" => "John Smith", "age" => 70)
[287] Fix | Delete
# person[:age] # => 70, same as person.age
[288] Fix | Delete
#
[289] Fix | Delete
def [](name)
[290] Fix | Delete
@table[name.to_sym]
[291] Fix | Delete
end
[292] Fix | Delete
[293] Fix | Delete
#
[294] Fix | Delete
# :call-seq:
[295] Fix | Delete
# ostruct[name] = obj -> obj
[296] Fix | Delete
#
[297] Fix | Delete
# Sets the value of an attribute.
[298] Fix | Delete
#
[299] Fix | Delete
# require "ostruct"
[300] Fix | Delete
# person = OpenStruct.new("name" => "John Smith", "age" => 70)
[301] Fix | Delete
# person[:age] = 42 # equivalent to person.age = 42
[302] Fix | Delete
# person.age # => 42
[303] Fix | Delete
#
[304] Fix | Delete
def []=(name, value)
[305] Fix | Delete
name = name.to_sym
[306] Fix | Delete
new_ostruct_member!(name)
[307] Fix | Delete
@table[name] = value
[308] Fix | Delete
end
[309] Fix | Delete
alias_method :set_ostruct_member_value!, :[]=
[310] Fix | Delete
private :set_ostruct_member_value!
[311] Fix | Delete
[312] Fix | Delete
# :call-seq:
[313] Fix | Delete
# ostruct.dig(name, *identifiers) -> object
[314] Fix | Delete
#
[315] Fix | Delete
# Finds and returns the object in nested objects
[316] Fix | Delete
# that is specified by +name+ and +identifiers+.
[317] Fix | Delete
# The nested objects may be instances of various classes.
[318] Fix | Delete
# See {Dig Methods}[rdoc-ref:dig_methods.rdoc].
[319] Fix | Delete
#
[320] Fix | Delete
# Examples:
[321] Fix | Delete
# require "ostruct"
[322] Fix | Delete
# address = OpenStruct.new("city" => "Anytown NC", "zip" => 12345)
[323] Fix | Delete
# person = OpenStruct.new("name" => "John Smith", "address" => address)
[324] Fix | Delete
# person.dig(:address, "zip") # => 12345
[325] Fix | Delete
# person.dig(:business_address, "zip") # => nil
[326] Fix | Delete
def dig(name, *names)
[327] Fix | Delete
begin
[328] Fix | Delete
name = name.to_sym
[329] Fix | Delete
rescue NoMethodError
[330] Fix | Delete
raise! TypeError, "#{name} is not a symbol nor a string"
[331] Fix | Delete
end
[332] Fix | Delete
@table.dig(name, *names)
[333] Fix | Delete
end
[334] Fix | Delete
[335] Fix | Delete
#
[336] Fix | Delete
# Removes the named field from the object and returns the value the field
[337] Fix | Delete
# contained if it was defined. You may optionally provide a block.
[338] Fix | Delete
# If the field is not defined, the result of the block is returned,
[339] Fix | Delete
# or a NameError is raised if no block was given.
[340] Fix | Delete
#
[341] Fix | Delete
# require "ostruct"
[342] Fix | Delete
#
[343] Fix | Delete
# person = OpenStruct.new(name: "John", age: 70, pension: 300)
[344] Fix | Delete
#
[345] Fix | Delete
# person.delete_field!("age") # => 70
[346] Fix | Delete
# person # => #<OpenStruct name="John", pension=300>
[347] Fix | Delete
#
[348] Fix | Delete
# Setting the value to +nil+ will not remove the attribute:
[349] Fix | Delete
#
[350] Fix | Delete
# person.pension = nil
[351] Fix | Delete
# person # => #<OpenStruct name="John", pension=nil>
[352] Fix | Delete
#
[353] Fix | Delete
# person.delete_field('number') # => NameError
[354] Fix | Delete
#
[355] Fix | Delete
# person.delete_field('number') { 8675_309 } # => 8675309
[356] Fix | Delete
#
[357] Fix | Delete
def delete_field(name, &block)
[358] Fix | Delete
sym = name.to_sym
[359] Fix | Delete
begin
[360] Fix | Delete
singleton_class.remove_method(sym, "#{sym}=")
[361] Fix | Delete
rescue NameError
[362] Fix | Delete
end
[363] Fix | Delete
@table.delete(sym) do
[364] Fix | Delete
return yield if block
[365] Fix | Delete
raise! NameError.new("no field `#{sym}' in #{self}", sym)
[366] Fix | Delete
end
[367] Fix | Delete
end
[368] Fix | Delete
[369] Fix | Delete
InspectKey = :__inspect_key__ # :nodoc:
[370] Fix | Delete
[371] Fix | Delete
#
[372] Fix | Delete
# Returns a string containing a detailed summary of the keys and values.
[373] Fix | Delete
#
[374] Fix | Delete
def inspect
[375] Fix | Delete
ids = (Thread.current[InspectKey] ||= [])
[376] Fix | Delete
if ids.include?(object_id)
[377] Fix | Delete
detail = ' ...'
[378] Fix | Delete
else
[379] Fix | Delete
ids << object_id
[380] Fix | Delete
begin
[381] Fix | Delete
detail = @table.map do |key, value|
[382] Fix | Delete
" #{key}=#{value.inspect}"
[383] Fix | Delete
end.join(',')
[384] Fix | Delete
ensure
[385] Fix | Delete
ids.pop
[386] Fix | Delete
end
[387] Fix | Delete
end
[388] Fix | Delete
['#<', self.class!, detail, '>'].join
[389] Fix | Delete
end
[390] Fix | Delete
alias :to_s :inspect
[391] Fix | Delete
[392] Fix | Delete
attr_reader :table # :nodoc:
[393] Fix | Delete
alias table! table
[394] Fix | Delete
protected :table!
[395] Fix | Delete
[396] Fix | Delete
#
[397] Fix | Delete
# Compares this object and +other+ for equality. An OpenStruct is equal to
[398] Fix | Delete
# +other+ when +other+ is an OpenStruct and the two objects' Hash tables are
[399] Fix | Delete
# equal.
[400] Fix | Delete
#
[401] Fix | Delete
# require "ostruct"
[402] Fix | Delete
# first_pet = OpenStruct.new("name" => "Rowdy")
[403] Fix | Delete
# second_pet = OpenStruct.new(:name => "Rowdy")
[404] Fix | Delete
# third_pet = OpenStruct.new("name" => "Rowdy", :age => nil)
[405] Fix | Delete
#
[406] Fix | Delete
# first_pet == second_pet # => true
[407] Fix | Delete
# first_pet == third_pet # => false
[408] Fix | Delete
#
[409] Fix | Delete
def ==(other)
[410] Fix | Delete
return false unless other.kind_of?(OpenStruct)
[411] Fix | Delete
@table == other.table!
[412] Fix | Delete
end
[413] Fix | Delete
[414] Fix | Delete
#
[415] Fix | Delete
# Compares this object and +other+ for equality. An OpenStruct is eql? to
[416] Fix | Delete
# +other+ when +other+ is an OpenStruct and the two objects' Hash tables are
[417] Fix | Delete
# eql?.
[418] Fix | Delete
#
[419] Fix | Delete
def eql?(other)
[420] Fix | Delete
return false unless other.kind_of?(OpenStruct)
[421] Fix | Delete
@table.eql?(other.table!)
[422] Fix | Delete
end
[423] Fix | Delete
[424] Fix | Delete
# Computes a hash code for this OpenStruct.
[425] Fix | Delete
def hash # :nodoc:
[426] Fix | Delete
@table.hash
[427] Fix | Delete
end
[428] Fix | Delete
[429] Fix | Delete
#
[430] Fix | Delete
# Provides marshalling support for use by the YAML library.
[431] Fix | Delete
#
[432] Fix | Delete
def encode_with(coder) # :nodoc:
[433] Fix | Delete
@table.each_pair do |key, value|
[434] Fix | Delete
coder[key.to_s] = value
[435] Fix | Delete
end
[436] Fix | Delete
if @table.size == 1 && @table.key?(:table) # support for legacy format
[437] Fix | Delete
# in the very unlikely case of a single entry called 'table'
[438] Fix | Delete
coder['legacy_support!'] = true # add a bogus second entry
[439] Fix | Delete
end
[440] Fix | Delete
end
[441] Fix | Delete
[442] Fix | Delete
#
[443] Fix | Delete
# Provides marshalling support for use by the YAML library.
[444] Fix | Delete
#
[445] Fix | Delete
def init_with(coder) # :nodoc:
[446] Fix | Delete
h = coder.map
[447] Fix | Delete
if h.size == 1 # support for legacy format
[448] Fix | Delete
key, val = h.first
[449] Fix | Delete
if key == 'table'
[450] Fix | Delete
h = val
[451] Fix | Delete
end
[452] Fix | Delete
end
[453] Fix | Delete
update_to_values!(h)
[454] Fix | Delete
end
[455] Fix | Delete
[456] Fix | Delete
# Make all public methods (builtin or our own) accessible with <code>!</code>:
[457] Fix | Delete
give_access = instance_methods
[458] Fix | Delete
# See https://github.com/ruby/ostruct/issues/30
[459] Fix | Delete
give_access -= %i[instance_exec instance_eval eval] if RUBY_ENGINE == 'jruby'
[460] Fix | Delete
give_access.each do |method|
[461] Fix | Delete
next if method.match(/\W$/)
[462] Fix | Delete
[463] Fix | Delete
new_name = "#{method}!"
[464] Fix | Delete
alias_method new_name, method
[465] Fix | Delete
end
[466] Fix | Delete
# Other builtin private methods we use:
[467] Fix | Delete
alias_method :raise!, :raise
[468] Fix | Delete
private :raise!
[469] Fix | Delete
[470] Fix | Delete
# See https://github.com/ruby/ostruct/issues/40
[471] Fix | Delete
if RUBY_ENGINE != 'jruby'
[472] Fix | Delete
alias_method :block_given!, :block_given?
[473] Fix | Delete
private :block_given!
[474] Fix | Delete
end
[475] Fix | Delete
end
[476] Fix | Delete
[477] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function