crstruct 0.1.191207 → 0.1.210920
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/README.md +57 -79
- data/lib/crstruct/open.rb +1 -2
- data/lib/crstruct/registered.rb +0 -1
- data/lib/crstruct.rb +2 -2
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfe7c0590726e9eb559dc81a08b23c3867cfea18ef838ee5c28a5ae77cd4ee6b
|
4
|
+
data.tar.gz: b8b79defb6d76340f1f990903c8b48a72d25b02a9daa172bb22853a073f22752
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b3932c83bcb8dbbcfe8f407296719d3655e488cc1ab357586d4a941f7a7af478a58361201509071ccfc9b107bc78548bfa73384e93aadf23012eca22dfb7c33
|
7
|
+
data.tar.gz: 59ab70e0cc26137e1b70a04bad5049374031222deacefe348b2ca2cbb6872dcebdee8c70cd2638cb44e532dbbf3c46cb1da7cdbe2e1a6493ec4c2baddc46f5cf
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# crstruct
|
2
2
|
|
3
|
+
* [VERSION 0.1.210920](https://www.github.com/carlosjhr64/crstruct/releases)
|
3
4
|
* [github](https://www.github.com/carlosjhr64/crstruct)
|
4
5
|
* [rubygems](https://rubygems.org/gems/crstruct)
|
5
6
|
|
@@ -13,97 +14,74 @@ no "Update"...
|
|
13
14
|
no "Delete".
|
14
15
|
|
15
16
|
## INSTALL:
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
```console
|
18
|
+
$ gem install crstruct
|
19
|
+
```
|
19
20
|
## SYNOPSIS
|
20
21
|
|
21
22
|
The following shows the intended use of CRStruct::Open:
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
|
23
|
+
```ruby
|
24
|
+
require 'crstruct'
|
25
|
+
|
26
|
+
s = CRStruct::Open.new
|
27
|
+
s.a = "A"
|
28
|
+
s.a #=> "A"
|
29
|
+
|
30
|
+
begin
|
31
|
+
# Not allowed to reset s.a...
|
32
|
+
s.a = "B" # raises error
|
33
|
+
# as there's no actual s.a=...
|
34
|
+
rescue NoMethodError
|
35
|
+
s.b = "B"
|
36
|
+
end
|
37
|
+
s.a #=> "A"
|
38
|
+
s.b #=> "B"
|
39
|
+
|
40
|
+
if s.b == "B"
|
41
|
+
begin
|
42
|
+
s.c # There is no s.c so raises
|
43
|
+
rescue NoMethodError
|
44
|
+
s.c = "C"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
s.a #=> "A"
|
48
|
+
s.b #=> "B"
|
49
|
+
s.c #=> "C"
|
50
|
+
```
|
52
51
|
There's also a subclass CRStruct::Registered:
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
# #<CRStruct::Registered:0x0000561d37006b08
|
67
|
-
# @h={:a=>"A", :b=>"B", :c=>"C"},
|
68
|
-
# @r=[:a, :b, :c]>
|
69
|
-
pp s
|
70
|
-
|
71
|
-
|
52
|
+
```ruby
|
53
|
+
s = CRStruct::Registered.new :a, :b, :c
|
54
|
+
s.a = "A"
|
55
|
+
s.b = "B"
|
56
|
+
s.c = "C"
|
57
|
+
begin
|
58
|
+
s.d = "D"
|
59
|
+
rescue NoMethodError
|
60
|
+
# Can't set :d as it was not registered with s.
|
61
|
+
end
|
62
|
+
s
|
63
|
+
#~> ^#<CRStruct::Registered:0x\h+ @r=\[:a, :b, :c\], @h=\{:a=>"A", :b=>"B", :c=>"C"\}>$
|
64
|
+
```
|
72
65
|
## MORE
|
73
66
|
|
74
67
|
The following can be done, but
|
75
68
|
you'd be circumventing the intended use:
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
# s.c is C
|
88
|
-
# s.d is nil
|
89
|
-
puts "s.a is #{s.get?(:a)}"
|
90
|
-
puts "s.b is #{s.get?(:b)}"
|
91
|
-
puts "s.c is #{s.get?(:c)}"
|
92
|
-
puts "s.d is #{s.get?(:d)}"
|
93
|
-
# Output:
|
94
|
-
# {:a=>"A", :b=>"B", :c=>"C"}
|
95
|
-
pp s.to_h
|
96
|
-
end
|
97
|
-
|
98
|
-
# The :free? method determines if a Symbol is avaible for setting.
|
99
|
-
s.free?(:to_s) #=> false
|
100
|
-
s.free?(:d) #=> true
|
101
|
-
|
69
|
+
```ruby
|
70
|
+
s = CRStruct::Open.new a: "A", b: "B"
|
71
|
+
s.get?(:c) #=> nil
|
72
|
+
s.set!(:c, "C")
|
73
|
+
s.get?(:c) #=> "C"
|
74
|
+
s.c #=> "C"
|
75
|
+
|
76
|
+
# The :free? method determines if a Symbol is available for setting.
|
77
|
+
s.free?(:to_s) #=> false
|
78
|
+
s.free?(:d) #=> true
|
79
|
+
```
|
102
80
|
## LICENSE:
|
103
81
|
|
104
82
|
(The MIT License)
|
105
83
|
|
106
|
-
Copyright (c)
|
84
|
+
Copyright (c) 2021 CarlosJHR64
|
107
85
|
|
108
86
|
Permission is hereby granted, free of charge, to any person obtaining
|
109
87
|
a copy of this software and associated documentation files (the
|
data/lib/crstruct/open.rb
CHANGED
@@ -16,7 +16,7 @@ module CRStruct
|
|
16
16
|
|
17
17
|
#########################################
|
18
18
|
### free?, set!, and get? ###
|
19
|
-
# make
|
19
|
+
# make purposeful access to @h possible,
|
20
20
|
# and easier to subclass CRStruct.
|
21
21
|
#########################################
|
22
22
|
|
@@ -46,4 +46,3 @@ module CRStruct
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
data/lib/crstruct/registered.rb
CHANGED
data/lib/crstruct.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crstruct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.210920
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- CarlosJHR64
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Ruby gem for an extremely lite OpenStruct like class with
|
@@ -30,7 +30,7 @@ homepage: https://github.com/carlosjhr64/crstruct
|
|
30
30
|
licenses:
|
31
31
|
- MIT
|
32
32
|
metadata: {}
|
33
|
-
post_install_message:
|
33
|
+
post_install_message:
|
34
34
|
rdoc_options: []
|
35
35
|
require_paths:
|
36
36
|
- lib
|
@@ -45,9 +45,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
requirements:
|
48
|
-
- 'ruby: ruby
|
49
|
-
rubygems_version: 3.
|
50
|
-
signing_key:
|
48
|
+
- 'ruby: ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]'
|
49
|
+
rubygems_version: 3.2.22
|
50
|
+
signing_key:
|
51
51
|
specification_version: 4
|
52
52
|
summary: Ruby gem for an extremely lite OpenStruct like class with attributes that
|
53
53
|
can only be set once, and then read thereafter.
|