better_struct 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/better_struct.rb +1 -5
- data/lib/better_struct/version.rb +1 -1
- data/test/better_struct_test.rb +5 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c66dda2acf77cbc9d8335a5566a4c7ceb6b08c3
|
4
|
+
data.tar.gz: 4b89de754a58102d32eece33e3299fa4acd44db1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3247b8c76980dd91b2e463c150e27555cbf4714f898fc8e40938d2b952d6e2c3896722e0a8c3d7e7fe3edc4d94931ad6c17ff35dea4db7663e5f29818d320ec
|
7
|
+
data.tar.gz: 6d601f5ce53b1c0d66ac0185fb5df718041be0abc976e19df56715888ba21a249934ad798e63307343d6f06ce31eac2293ff764a6aab4f5ab16a4f90c86cb32e
|
data/README.md
CHANGED
@@ -32,13 +32,13 @@ BetterStruct.new(nil) == BetterStruct.new(nil).some_method # => true
|
|
32
32
|
```ruby
|
33
33
|
better_struct = BetterStruct.new("foobar")
|
34
34
|
|
35
|
-
|
36
35
|
better_struct[0..2].is_a?(BetterStruct) # => true
|
37
36
|
better_struct[0..2] == BetterStruct.new("foo") # => true
|
38
37
|
```
|
39
38
|
|
40
39
|
```ruby
|
41
40
|
better_struct = BetterStruct.new([1, 2, 3])
|
41
|
+
|
42
42
|
result = better_struct.all? { |i| i.is_a?(BetterStruct) }
|
43
43
|
|
44
44
|
result.is_a?(BetterStruct) # => true
|
@@ -49,7 +49,8 @@ result == BetterStruct.new(true) # => true
|
|
49
49
|
#### Like OpenStruct
|
50
50
|
|
51
51
|
```ruby
|
52
|
-
|
52
|
+
some_hash = { "FooBar1" => { foo_bar2: "Hello World!" } }
|
53
|
+
better_struct = BetterStruct.new(some_hash)
|
53
54
|
|
54
55
|
better_struct.foo_bar1.foo_bar2 == BetterStruct.new("Hello World!") # => true
|
55
56
|
```
|
@@ -58,9 +59,8 @@ better_struct.foo_bar1.foo_bar2 == BetterStruct.new("Hello World!") # => true
|
|
58
59
|
|
59
60
|
```ruby
|
60
61
|
better_struct = BetterStruct.new("foobar")
|
61
|
-
new_better_struct = better_struct.gsub("foo", "super-")
|
62
62
|
|
63
|
-
|
63
|
+
better_struct.gsub("foo", "super-").value == "super-foo" # => true
|
64
64
|
|
65
65
|
```
|
66
66
|
|
data/lib/better_struct.rb
CHANGED
@@ -53,12 +53,8 @@ private
|
|
53
53
|
|
54
54
|
if value.respond_to?(method_name)
|
55
55
|
wrap(value.public_send(*args, &wrap_block_arguments(*args, &block)))
|
56
|
-
elsif @defined_methods[method_name] || value.nil?
|
57
|
-
wrap(@defined_methods[method_name])
|
58
56
|
else
|
59
|
-
|
60
|
-
error.set_backtrace caller(1)
|
61
|
-
raise error
|
57
|
+
wrap(@defined_methods[method_name])
|
62
58
|
end
|
63
59
|
end
|
64
60
|
end
|
data/test/better_struct_test.rb
CHANGED
@@ -28,9 +28,11 @@ class BetterStructTest < Minitest::Test
|
|
28
28
|
def test_block_argument_wrapping
|
29
29
|
better_struct = BetterStruct.new([3, 2, 1])
|
30
30
|
|
31
|
-
better_struct.each_with_index do |
|
32
|
-
|
33
|
-
|
31
|
+
better_struct.each_with_index do |val, i|
|
32
|
+
assert val.is_a?(BetterStruct)
|
33
|
+
assert val.value.is_a?(Integer)
|
34
|
+
assert i.is_a?(BetterStruct)
|
35
|
+
assert i.value.is_a?(Integer)
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|