ostruct 0.5.1 → 0.5.4
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/lib/ostruct.rb +16 -8
- data/ostruct.gemspec +0 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eac2df904d6f8e5f05be36be58b316b427d242d1e9d49393158c9dad9ea0b1cc
|
4
|
+
data.tar.gz: 3ce7d400c329fdd87068795d39af61573067e1823b416c7a64d3bda505e1aae8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26522368cd5bbd3c8ef3f16e64629f9a9d85b9cae1b042a184185642cf90b554e46bf499c27d0858165b5add821ef82c544d67e2a0a910708a23c6d1d88713df
|
7
|
+
data.tar.gz: 5b767ef21b4c28d0653cf8d8437a38bc3b0497bbfaf315db3d32b94f490f0b36e28330fff1bb3c0f5e67e5c2ab4d414615bc65b1426d0588e8d2b1da8ccf9b78
|
data/lib/ostruct.rb
CHANGED
@@ -107,7 +107,7 @@
|
|
107
107
|
# For all these reasons, consider not using OpenStruct at all.
|
108
108
|
#
|
109
109
|
class OpenStruct
|
110
|
-
VERSION = "0.5.
|
110
|
+
VERSION = "0.5.4"
|
111
111
|
|
112
112
|
#
|
113
113
|
# Creates a new OpenStruct object. By default, the resulting OpenStruct
|
@@ -221,11 +221,14 @@ class OpenStruct
|
|
221
221
|
#
|
222
222
|
def new_ostruct_member!(name) # :nodoc:
|
223
223
|
unless @table.key?(name) || is_method_protected!(name)
|
224
|
-
getter_proc = Proc.new { @table[name] }
|
225
|
-
setter_proc = Proc.new {|x| @table[name] = x}
|
226
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
227
|
::Ractor.make_shareable(getter_proc)
|
228
228
|
::Ractor.make_shareable(setter_proc)
|
229
|
+
else
|
230
|
+
getter_proc = Proc.new { @table[name] }
|
231
|
+
setter_proc = Proc.new {|x| @table[name] = x}
|
229
232
|
end
|
230
233
|
define_singleton_method!(name, &getter_proc)
|
231
234
|
define_singleton_method!("#{name}=", &setter_proc)
|
@@ -243,7 +246,7 @@ class OpenStruct
|
|
243
246
|
if owner.class == ::Class
|
244
247
|
owner < ::OpenStruct
|
245
248
|
else
|
246
|
-
self.class
|
249
|
+
self.class!.ancestors.any? do |mod|
|
247
250
|
return false if mod == ::OpenStruct
|
248
251
|
mod == owner
|
249
252
|
end
|
@@ -353,14 +356,14 @@ class OpenStruct
|
|
353
356
|
#
|
354
357
|
# person.delete_field('number') { 8675_309 } # => 8675309
|
355
358
|
#
|
356
|
-
def delete_field(name)
|
359
|
+
def delete_field(name, &block)
|
357
360
|
sym = name.to_sym
|
358
361
|
begin
|
359
362
|
singleton_class.remove_method(sym, "#{sym}=")
|
360
363
|
rescue NameError
|
361
364
|
end
|
362
365
|
@table.delete(sym) do
|
363
|
-
return yield if
|
366
|
+
return yield if block
|
364
367
|
raise! NameError.new("no field `#{sym}' in #{self}", sym)
|
365
368
|
end
|
366
369
|
end
|
@@ -464,6 +467,11 @@ class OpenStruct
|
|
464
467
|
end
|
465
468
|
# Other builtin private methods we use:
|
466
469
|
alias_method :raise!, :raise
|
467
|
-
|
468
|
-
|
470
|
+
private :raise!
|
471
|
+
|
472
|
+
# See https://github.com/ruby/ostruct/issues/40
|
473
|
+
if RUBY_ENGINE != 'jruby'
|
474
|
+
alias_method :block_given!, :block_given?
|
475
|
+
private :block_given!
|
476
|
+
end
|
469
477
|
end
|
data/ostruct.gemspec
CHANGED
@@ -20,8 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.required_ruby_version = ">= 2.5.0"
|
21
21
|
|
22
22
|
spec.files = [".gitignore", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "bin/console", "bin/setup", "lib/ostruct.rb", "ostruct.gemspec"]
|
23
|
-
spec.bindir = "exe"
|
24
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
23
|
spec.require_paths = ["lib"]
|
26
24
|
|
27
25
|
spec.add_development_dependency "bundler"
|
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.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc-Andre Lafortune
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-24 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.
|