ostruct 0.4.0 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/ostruct.rb +26 -12
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dd6c110dc356e3b206754a307aebdcd546da5b22aa0dbfc95fe1e804213f3ef
|
4
|
+
data.tar.gz: c84e85b32c2b550068cb082ef1053b47238cad2af2647a6407637982cf6ae90c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b4f764595555d9f2be9ee8e339b9391d7d6fe3b3e8739e7bb69a0bcf8f0cca3852ec8d7b542cf8484f4f830bba95092f5801a7c7345c31352c0bb0ecc98ac5c
|
7
|
+
data.tar.gz: dce5c89e21deaf0f78a022e4e5e873f834f8b7090a6d74c7caf4c9c5fbf004f424018f28422addbd8324f5a5a444d5992bd057fddb3b736d7892c28b8cd06180
|
data/Rakefile
CHANGED
@@ -17,7 +17,7 @@ end
|
|
17
17
|
|
18
18
|
task :sync_tool do
|
19
19
|
require 'fileutils'
|
20
|
-
FileUtils.cp "../ruby/tool/lib/
|
20
|
+
FileUtils.cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
|
21
21
|
FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
|
22
22
|
FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
|
23
23
|
end
|
data/lib/ostruct.rb
CHANGED
@@ -93,21 +93,21 @@
|
|
93
93
|
# o.methods = [:foo, :bar]
|
94
94
|
# o.methods # => [:foo, :bar]
|
95
95
|
#
|
96
|
-
# To help remedy clashes, OpenStruct uses only protected/private methods ending with
|
97
|
-
# and defines aliases for builtin public methods by adding a
|
96
|
+
# To help remedy clashes, OpenStruct uses only protected/private methods ending with <code>!</code>
|
97
|
+
# and defines aliases for builtin public methods by adding a <code>!</code>:
|
98
98
|
#
|
99
99
|
# o = OpenStruct.new(make: 'Bentley', class: :luxury)
|
100
100
|
# o.class # => :luxury
|
101
101
|
# o.class! # => OpenStruct
|
102
102
|
#
|
103
|
-
# It is recommended (but not enforced) to not use fields ending in
|
103
|
+
# It is recommended (but not enforced) to not use fields ending in <code>!</code>;
|
104
104
|
# Note that a subclass' methods may not be overwritten, nor can OpenStruct's own methods
|
105
|
-
# ending with
|
105
|
+
# ending with <code>!</code>.
|
106
106
|
#
|
107
107
|
# For all these reasons, consider not using OpenStruct at all.
|
108
108
|
#
|
109
109
|
class OpenStruct
|
110
|
-
VERSION = "0.
|
110
|
+
VERSION = "0.5.3"
|
111
111
|
|
112
112
|
#
|
113
113
|
# Creates a new OpenStruct object. By default, the resulting OpenStruct
|
@@ -221,8 +221,17 @@ class OpenStruct
|
|
221
221
|
#
|
222
222
|
def new_ostruct_member!(name) # :nodoc:
|
223
223
|
unless @table.key?(name) || is_method_protected!(name)
|
224
|
-
|
225
|
-
|
224
|
+
if defined?(::Ractor)
|
225
|
+
getter_proc = nil.instance_eval{ Proc.new { @table[name] } }
|
226
|
+
setter_proc = nil.instance_eval{ Proc.new {|x| @table[name] = x} }
|
227
|
+
::Ractor.make_shareable(getter_proc)
|
228
|
+
::Ractor.make_shareable(setter_proc)
|
229
|
+
else
|
230
|
+
getter_proc = Proc.new { @table[name] }
|
231
|
+
setter_proc = Proc.new {|x| @table[name] = x}
|
232
|
+
end
|
233
|
+
define_singleton_method!(name, &getter_proc)
|
234
|
+
define_singleton_method!("#{name}=", &setter_proc)
|
226
235
|
end
|
227
236
|
end
|
228
237
|
private :new_ostruct_member!
|
@@ -237,7 +246,7 @@ class OpenStruct
|
|
237
246
|
if owner.class == ::Class
|
238
247
|
owner < ::OpenStruct
|
239
248
|
else
|
240
|
-
self.class
|
249
|
+
self.class!.ancestors.any? do |mod|
|
241
250
|
return false if mod == ::OpenStruct
|
242
251
|
mod == owner
|
243
252
|
end
|
@@ -273,7 +282,7 @@ class OpenStruct
|
|
273
282
|
# :call-seq:
|
274
283
|
# ostruct[name] -> object
|
275
284
|
#
|
276
|
-
# Returns the value of an attribute, or
|
285
|
+
# Returns the value of an attribute, or +nil+ if there is no such attribute.
|
277
286
|
#
|
278
287
|
# require "ostruct"
|
279
288
|
# person = OpenStruct.new("name" => "John Smith", "age" => 70)
|
@@ -308,7 +317,7 @@ class OpenStruct
|
|
308
317
|
# Finds and returns the object in nested objects
|
309
318
|
# that is specified by +name+ and +identifiers+.
|
310
319
|
# The nested objects may be instances of various classes.
|
311
|
-
# See {Dig Methods}[rdoc-ref:
|
320
|
+
# See {Dig Methods}[rdoc-ref:dig_methods.rdoc].
|
312
321
|
#
|
313
322
|
# Examples:
|
314
323
|
# require "ostruct"
|
@@ -446,8 +455,13 @@ class OpenStruct
|
|
446
455
|
update_to_values!(h)
|
447
456
|
end
|
448
457
|
|
449
|
-
# Make all public methods (builtin or our own) accessible with
|
450
|
-
|
458
|
+
# Make all public methods (builtin or our own) accessible with <code>!</code>:
|
459
|
+
give_access = instance_methods
|
460
|
+
# See https://github.com/ruby/ostruct/issues/30
|
461
|
+
give_access -= %i[instance_exec instance_eval eval] if RUBY_ENGINE == 'jruby'
|
462
|
+
give_access.each do |method|
|
463
|
+
next if method.match(/\W$/)
|
464
|
+
|
451
465
|
new_name = "#{method}!"
|
452
466
|
alias_method new_name, method
|
453
467
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ostruct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc-Andre Lafortune
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
|
-
rubygems_version: 3.
|
77
|
+
rubygems_version: 3.3.3
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: Class to build custom data structures, similar to a Hash.
|