Vendor mruby-object-ext into Kernel
@@ -19,22 +19,6 @@ class UncaughtThrowError < ArgumentError
end
module Kernel
- # Throws an object, uncaught throws will bubble up through other catch blocks.
- #
- # @param [Symbol] tag tag being thrown
- # @param [Object] value a value to return to the catch block
- # @raises [UncaughtThrowError]
- # @return [void] it will never return normally.
- #
- # @example
- # catch :ball do
- # pitcher.wind_up
- # throw :ball
- # end
- def throw(tag, value = nil)
- raise UncaughtThrowError.new(tag, value)
- end
-
# Setup a catch block and wait for an object to be thrown, the
# catch end without catching anything.
#
@@ -61,4 +45,32 @@ module Kernel
def not_set?
self == NOT_SET
end
+
+ def tap
+ yield self
+ self
+ end
+
+ # Throws an object, uncaught throws will bubble up through other catch blocks.
+ #
+ # @param [Symbol] tag tag being thrown
+ # @param [Object] value a value to return to the catch block
+ # @raises [UncaughtThrowError]
+ # @return [void] it will never return normally.
+ #
+ # @example
+ # catch :ball do
+ # pitcher.wind_up
+ # throw :ball
+ # end
+ def throw(tag, value = nil)
+ raise UncaughtThrowError.new(tag, value)
+ end
+
+ def yield_self(&block)
+ return to_enum :yield_self unless block
+ block.call(self)
+ end
+
+ alias then yield_self
end
