rstructural 0.3.1 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68d3611d22597d67e3a4d481d07cce3e029544f1852d05c32dd84c7fea4f2426
4
- data.tar.gz: '06693abe983552f132d9874780e8d1c1be0a33d4e41b3a1078a214f888796034'
3
+ metadata.gz: 19b715e16b32cd82a10871b0c6348c36e579d096130452409f58a0f5fdbf5326
4
+ data.tar.gz: e1649f6c0b33922125ab134ed4da189748e3a09c71968d04fe5f2f4027273357
5
5
  SHA512:
6
- metadata.gz: 8d8ed0bf31f77f652bc6392e161560e4fd410fa148d84acd39b3ae558347d9d0c43e98555534815121ef2c9d641a6f49373199a0aafefd11b8ebd97ddeeabe37
7
- data.tar.gz: 36a15de7dad8594103c8e2e0dd9ed0e3b7b9dbea72aa227e13c3824caf2340bff534d40c8ab55abf0d357f69a3c8a6fc51f3c20099e6426bb292aedb21f53e6a
6
+ metadata.gz: 9e23fdf733e52dcbd316b4bc96afa60689b3ccd63cd1c9de99103b2adf7557710c2d6ca92c954c9aaa8dbfcd18dac1bbbbda88ab39f1e8365051b658e944ed95
7
+ data.tar.gz: c1a3dbf70f81a1b654175b9154f8b6ac14c8b1f4c80b3f89eafc1cfebe6cc40b6cdb238eba8c80b06cecad8f5e78854f9bd9025396b93f049f432d4a718570cd
@@ -15,9 +15,13 @@ module Rstructural::Either
15
15
  Right.new(obj)
16
16
  end
17
17
 
18
- def self.try(&block)
18
+ def self.try(catch_nil: false, &block)
19
19
  result = block.call
20
- Right.new(result)
20
+ if catch_nil && result.nil?
21
+ Left.new(nil)
22
+ else
23
+ Right.new(result)
24
+ end
21
25
  rescue => e
22
26
  Left.new(e)
23
27
  end
@@ -30,6 +30,10 @@ module Rstructural
30
30
  "#{class_name}"
31
31
  end
32
32
 
33
+ def self.to_s
34
+ "<#{class_name}>"
35
+ end
36
+
33
37
  def [](key)
34
38
  _key = ("@" + key.to_s).to_sym
35
39
  self.instance_variable_get(_key)
@@ -44,7 +48,7 @@ module Rstructural
44
48
  if #{attributes.empty?}
45
49
  "#{class_name}"
46
50
  else
47
- __attrs = Array[#{attributes.map { |attr| "'#{attr}: ' + @#{attr}.to_s" }.join(', ')}].join(", ")
51
+ __attrs = Array[#{attributes.map { |attr| "'#{attr}: ' + (@#{attr}.nil? ? 'nil' : @#{attr}.to_s)" }.join(', ')}].join(", ")
48
52
  "#{class_name}(" + __attrs + ")"
49
53
  end
50
54
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "rstructural"
3
- spec.version = "0.3.1"
3
+ spec.version = "0.3.2"
4
4
  spec.authors = ["petitviolet"]
5
5
  spec.email = ["violethero0820@gmail.com"]
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rstructural
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - petitviolet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-31 00:00:00.000000000 Z
11
+ date: 2020-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug