active_object 5.8.7 → 5.8.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -5
- data/lib/active_object/object.rb +11 -1
- data/lib/active_object/version.rb +1 -1
- 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: 467b3ff3ed965d1993beb11434c8ead0d178a0c13fdb2c084d9653c8879a5276
|
4
|
+
data.tar.gz: f58d3b7bb9526ccdb2ccd8be5010e90e15e4b7f6ebcd58adc1c096e07da9b950
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03abb73322c9a69e9a65012cceaa2117c4301e2cbbe982b28e4a70eadf83c482b4f2a120330738ebd8d64309e46ea28245cbef1754441d9cc08e2b8a900ea8f3
|
7
|
+
data.tar.gz: 85b759f31eee8fd41fbceddc930aa3cce754a521f8395068e1f7d104eb12421b6e589e1404ce60e064a9448f7370e9e2cdacbb10e30ce4066a9cfe590d7786dc
|
data/README.md
CHANGED
@@ -1562,8 +1562,18 @@ true.falsey? #=> false
|
|
1562
1562
|
1.range? #=> false
|
1563
1563
|
```
|
1564
1564
|
|
1565
|
+
**Safe Call:**
|
1566
|
+
`safe_call` execute caller to an object and rescues with self.
|
1567
|
+
|
1568
|
+
```ruby
|
1569
|
+
callr = -> { 3 * 3 }
|
1570
|
+
|
1571
|
+
3.safe_call #=> 3
|
1572
|
+
callr.safe_call #=> 9
|
1573
|
+
```
|
1574
|
+
|
1565
1575
|
**Safe Send:**
|
1566
|
-
`safe_send` execute
|
1576
|
+
`safe_send` execute object method and rescues with self.
|
1567
1577
|
|
1568
1578
|
```ruby
|
1569
1579
|
3.safe_send(:fake) #=> 3
|
@@ -1657,13 +1667,23 @@ false.truthy? #=> false
|
|
1657
1667
|
'example'.try(:fake_method) #=> nil
|
1658
1668
|
```
|
1659
1669
|
|
1670
|
+
**Try Call:**
|
1671
|
+
`try_call` execute caller to an object and rescues with nil.
|
1672
|
+
|
1673
|
+
```ruby
|
1674
|
+
callr = -> { 3 * 3 }
|
1675
|
+
|
1676
|
+
3.try_call #=> nil
|
1677
|
+
callr.try_call #=> 9
|
1678
|
+
```
|
1679
|
+
|
1660
1680
|
**Try Send:**
|
1661
|
-
`try_send` execute
|
1681
|
+
`try_send` execute object method and rescues with nil.
|
1662
1682
|
|
1663
1683
|
```ruby
|
1664
|
-
3.
|
1665
|
-
3.
|
1666
|
-
3.
|
1684
|
+
3.try_send(:fake) #=> 3
|
1685
|
+
3.try_send(:to_s) #=> '3'
|
1686
|
+
3.try_send(:+, 2) #=> 5
|
1667
1687
|
```
|
1668
1688
|
|
1669
1689
|
## Range
|
data/lib/active_object/object.rb
CHANGED
@@ -69,8 +69,12 @@ module ActiveObject
|
|
69
69
|
is_a?(Range)
|
70
70
|
end
|
71
71
|
|
72
|
+
def safe_call
|
73
|
+
try_call || self
|
74
|
+
end
|
75
|
+
|
72
76
|
def safe_send(*keys)
|
73
|
-
|
77
|
+
try_send(*keys) || self
|
74
78
|
end
|
75
79
|
|
76
80
|
def salvage(placeholder = '---')
|
@@ -125,6 +129,12 @@ module ActiveObject
|
|
125
129
|
end
|
126
130
|
end
|
127
131
|
|
132
|
+
def try_call
|
133
|
+
return unless respond_to?(:call)
|
134
|
+
|
135
|
+
call
|
136
|
+
end
|
137
|
+
|
128
138
|
def try_send(*keys)
|
129
139
|
send(*keys) rescue nil
|
130
140
|
end
|