ostruct 0.3.3 → 0.4.0
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 +10 -3
- data/lib/ostruct.rb +13 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 275ddcb1c14c6e9ce329eab097a2c56eb09b6a1b3a2c108bbccdf8a2d02013a1
|
4
|
+
data.tar.gz: 3dec8898394fb32823c69f28645cedd248da69f7371156553a24820c87b62e90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9afae5a172d6bb18e5cf6f55bcd48c822ea07a22f3edb2197629e2434b6af83609eb4c01f9f12bb6343be2f74585dd1945a75a063200babccfc80293cd85c25
|
7
|
+
data.tar.gz: eaa9370db72e1832db832a0b7f52763a226879e70e6f9ede84084fd9bf103389db454ce1944b915ae509746012d326d01df6ff24305ef25a0f305e42ccb417e1
|
data/Rakefile
CHANGED
@@ -10,9 +10,16 @@ require "bundler/gem_tasks"
|
|
10
10
|
require "rake/testtask"
|
11
11
|
|
12
12
|
Rake::TestTask.new(:test) do |t|
|
13
|
-
t.libs << "test
|
14
|
-
t.
|
15
|
-
t.test_files = FileList[
|
13
|
+
t.libs << "test/lib"
|
14
|
+
t.ruby_opts << "-rhelper"
|
15
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
16
|
+
end
|
17
|
+
|
18
|
+
task :sync_tool do
|
19
|
+
require 'fileutils'
|
20
|
+
FileUtils.cp "../ruby/tool/lib/test/unit/core_assertions.rb", "./test/lib"
|
21
|
+
FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
|
22
|
+
FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
|
16
23
|
end
|
17
24
|
|
18
25
|
task :default => [:test]
|
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.
|
110
|
+
VERSION = "0.4.0"
|
111
111
|
|
112
112
|
#
|
113
113
|
# Creates a new OpenStruct object. By default, the resulting OpenStruct
|
@@ -197,7 +197,7 @@ class OpenStruct
|
|
197
197
|
# data.each_pair.to_a # => [[:country, "Australia"], [:capital, "Canberra"]]
|
198
198
|
#
|
199
199
|
def each_pair
|
200
|
-
return to_enum(__method__) { @table.size } unless block_given
|
200
|
+
return to_enum(__method__) { @table.size } unless block_given!
|
201
201
|
@table.each_pair{|p| yield p}
|
202
202
|
self
|
203
203
|
end
|
@@ -326,8 +326,10 @@ class OpenStruct
|
|
326
326
|
end
|
327
327
|
|
328
328
|
#
|
329
|
-
# Removes the named field from the object
|
330
|
-
# contained if it was defined.
|
329
|
+
# Removes the named field from the object and returns the value the field
|
330
|
+
# contained if it was defined. You may optionally provide a block.
|
331
|
+
# If the field is not defined, the result of the block is returned,
|
332
|
+
# or a NameError is raised if no block was given.
|
331
333
|
#
|
332
334
|
# require "ostruct"
|
333
335
|
#
|
@@ -341,6 +343,10 @@ class OpenStruct
|
|
341
343
|
# person.pension = nil
|
342
344
|
# person # => #<OpenStruct name="John", pension=nil>
|
343
345
|
#
|
346
|
+
# person.delete_field('number') # => NameError
|
347
|
+
#
|
348
|
+
# person.delete_field('number') { 8675_309 } # => 8675309
|
349
|
+
#
|
344
350
|
def delete_field(name)
|
345
351
|
sym = name.to_sym
|
346
352
|
begin
|
@@ -348,6 +354,7 @@ class OpenStruct
|
|
348
354
|
rescue NameError
|
349
355
|
end
|
350
356
|
@table.delete(sym) do
|
357
|
+
return yield if block_given!
|
351
358
|
raise! NameError.new("no field `#{sym}' in #{self}", sym)
|
352
359
|
end
|
353
360
|
end
|
@@ -446,5 +453,6 @@ class OpenStruct
|
|
446
453
|
end
|
447
454
|
# Other builtin private methods we use:
|
448
455
|
alias_method :raise!, :raise
|
449
|
-
|
456
|
+
alias_method :block_given!, :block_given?
|
457
|
+
private :raise!, :block_given!
|
450
458
|
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.4.0
|
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: 2021-
|
11
|
+
date: 2021-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|