openstruct-from_hash.rb 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -6
- data/lib/openstruct-from_hash.rb +1 -1
- data/test/openstruct-from_hash_test.rb +7 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb3f2fdd1a4a83d3c5af39bdca949b282b4b0fae44783ddf6286d5caf6288c51
|
4
|
+
data.tar.gz: d7adb4baf9bfd95e355c6128523ecd4bb971f02d046b000df30a23d0fd8920c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a29c40221477bf32515ff9de498a0663f4bf78d3b7ccf8ab253ff2ad7faa41ca54682bb1f7a99989d3bfa7e841b91f3c8354d43475d371a5fffb417b349e5808
|
7
|
+
data.tar.gz: 4673e0b8a161fd0ac49e64aac5e7e068e1a08a136cc3224b95d061e38192525d7acbc347f6a19ff9d306908a31f92d25f98817760ccc208d08eb86ff11746a19
|
data/README.md
CHANGED
@@ -16,13 +16,16 @@ constructor for the OpenStruct class that is apart of Ruby's standard library.
|
|
16
16
|
```ruby
|
17
17
|
require 'ostruct'
|
18
18
|
require 'openstruct-from_hash'
|
19
|
-
obj = OpenStruct.from_hash(
|
20
|
-
|
21
|
-
|
19
|
+
obj = OpenStruct.from_hash(
|
20
|
+
str: 'foo',
|
21
|
+
ary: [{ number: 20 }],
|
22
|
+
person: { name: 'John', age: 21.5, friends: [{name: 'Amy'}] }
|
22
23
|
)
|
23
|
-
obj.str
|
24
|
-
obj.ary[0].number
|
25
|
-
obj.
|
24
|
+
obj.str # => 'foo'
|
25
|
+
obj.ary[0].number # => 20
|
26
|
+
obj.person.name # => 'John'
|
27
|
+
obj.person.age # => 21.5
|
28
|
+
obj.person.friends[0].name # => 'Amy'
|
26
29
|
```
|
27
30
|
|
28
31
|
## <a id='install'>Install</a>
|
data/lib/openstruct-from_hash.rb
CHANGED
@@ -6,12 +6,15 @@ require 'minitest/autorun'
|
|
6
6
|
|
7
7
|
class OpenStructTest < Minitest::Test
|
8
8
|
def test_from_hash_1
|
9
|
-
obj = OpenStruct.from_hash(
|
10
|
-
|
11
|
-
|
9
|
+
obj = OpenStruct.from_hash(
|
10
|
+
str: 'foo',
|
11
|
+
ary: [{ number: 20 }, BasicObject],
|
12
|
+
person: { name: 'John', friends: [{ name: 'Amy' }] }
|
13
|
+
)
|
12
14
|
assert_equal 'foo', obj.str
|
13
15
|
assert_equal 20, obj.ary[0].number
|
14
16
|
assert BasicObject === obj.ary[1]
|
15
|
-
assert_equal
|
17
|
+
assert_equal 'John', obj.person.name
|
18
|
+
assert_equal 'Amy', obj.person.friends[0].name
|
16
19
|
end
|
17
20
|
end
|