emanlib 0.1.2 → 1.0.0
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/lib/emanlib.rb +1 -1
- data/lib/patch/enum.rb +1 -1
- data/lib/patch/foobar.rb +25 -0
- data/lib/patch/lambda.rb +3 -1
- data/lib/patch/let.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: ee96e53bdb664ace9bf896327991a0be3f16c216c3a9760ed521ef9a226ee3ad
|
4
|
+
data.tar.gz: 4a13f22c6e332f1d997b3ce3118f7a02b63508fc5e9a9e69d2ea89bd27487908
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af9f21316eefedbe9f2c465c1ea67ae9a9697e018da5e3b9dc35f6542fcba7a49f858940f64d13571e621caaa60cf614e6bb4746aca5a44c49fdc3eab6e2f45a
|
7
|
+
data.tar.gz: eabb3c4f8e251fa7ea41dd2ba97b52b7745257bfb27d68f8c8dd176dcae0bde4542df0af1ae810a0af66ecc800a107079d7f2581649be6e6ea433871c8e9e54b
|
data/lib/emanlib.rb
CHANGED
data/lib/patch/enum.rb
CHANGED
data/lib/patch/foobar.rb
CHANGED
@@ -338,3 +338,28 @@ end
|
|
338
338
|
class Hash
|
339
339
|
alias flip invert
|
340
340
|
end
|
341
|
+
|
342
|
+
module Kernel
|
343
|
+
# Executes the given block and "parries" any caught StandardError,
|
344
|
+
# re-raising it as the specified klass with an optional custom message.
|
345
|
+
#
|
346
|
+
# @param klass [Class<StandardError>] The error class to re-raise if an error occurs.
|
347
|
+
# @param message [String, nil] An optional custom error message.
|
348
|
+
# If nil, the original error's message is used.
|
349
|
+
# @raise [klass] Raises the specified klass with the appropriate message.
|
350
|
+
def parry(klass, message = nil)
|
351
|
+
begin
|
352
|
+
yield
|
353
|
+
rescue StandardError => e
|
354
|
+
final_message = message || e.message
|
355
|
+
|
356
|
+
if e.is_a?(klass) && message.nil?
|
357
|
+
raise e
|
358
|
+
else
|
359
|
+
new_error = klass.new(final_message)
|
360
|
+
new_error.set_backtrace(e.backtrace)
|
361
|
+
raise new_error
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
data/lib/patch/lambda.rb
CHANGED
@@ -19,7 +19,7 @@ class Array
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
module
|
22
|
+
module Kernel
|
23
23
|
|
24
24
|
# A Lambda object (`_`) is building block for anonymous functions.
|
25
25
|
# For instance, (`_ + _`) represents f(x,y) = x + y
|
@@ -157,7 +157,9 @@ module EmanLib
|
|
157
157
|
# [1, 2, 3].map(&_.succ) => [2, 3, 4]
|
158
158
|
# [[1, 2], [3, 4]].map(&(_ + _).lift) => [3, 7]
|
159
159
|
_ = Lambda.new
|
160
|
+
end
|
160
161
|
|
162
|
+
module EmanLib
|
161
163
|
# Support for using a `_` as the second operand with operators.
|
162
164
|
# WARN: This method WILL MODIFY the standard library classes.
|
163
165
|
# In particular, the operators: `- * / % ** & | ^ << >> <=> == === != > < >= <=`
|
data/lib/patch/let.rb
CHANGED