diff options
author | yui-knk <spiketeika@gmail.com> | 2015-04-06 08:37:27 +0900 |
---|---|---|
committer | yui-knk <spiketeika@gmail.com> | 2015-04-06 08:37:27 +0900 |
commit | 1917719f003a2681b1f5ec00a54225457fcf0733 (patch) | |
tree | 8c98b21fdbccf2839dd715a382e7b2f7139aed7e /guides | |
parent | 9040699aed64a725cc66461d63f794abc2f13afc (diff) | |
download | rails-1917719f003a2681b1f5ec00a54225457fcf0733.tar.gz rails-1917719f003a2681b1f5ec00a54225457fcf0733.tar.bz2 rails-1917719f003a2681b1f5ec00a54225457fcf0733.zip |
[ci skip] Remove Extensions to `Proc` chapter section
`Proc#bind` is removed with 4.1 release
Diffstat (limited to 'guides')
-rw-r--r-- | guides/source/active_support_core_extensions.md | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index 5fb577e256..ff60f95a2c 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -3040,53 +3040,6 @@ The method `Range#overlaps?` says whether any two given ranges have non-void int NOTE: Defined in `active_support/core_ext/range/overlaps.rb`. -Extensions to `Proc` --------------------- - -### `bind` - -As you surely know Ruby has an `UnboundMethod` class whose instances are methods that belong to the limbo of methods without a self. The method `Module#instance_method` returns an unbound method for example: - -```ruby -Hash.instance_method(:delete) # => #<UnboundMethod: Hash#delete> -``` - -An unbound method is not callable as is, you need to bind it first to an object with `bind`: - -```ruby -clear = Hash.instance_method(:clear) -clear.bind({a: 1}).call # => {} -``` - -Active Support defines `Proc#bind` with an analogous purpose: - -```ruby -Proc.new { size }.bind([]).call # => 0 -``` - -As you see that's callable and bound to the argument, the return value is indeed a `Method`. - -NOTE: To do so `Proc#bind` actually creates a method under the hood. If you ever see a method with a weird name like `__bind_1256598120_237302` in a stack trace you know now where it comes from. - -Action Pack uses this trick in `rescue_from` for example, which accepts the name of a method and also a proc as callbacks for a given rescued exception. It has to call them in either case, so a bound method is returned by `handler_for_rescue`, thus simplifying the code in the caller: - -```ruby -def handler_for_rescue(exception) - _, rescuer = Array(rescue_handlers).reverse.detect do |klass_name, handler| - ... - end - - case rescuer - when Symbol - method(rescuer) - when Proc - rescuer.bind(self) - end -end -``` - -NOTE: Defined in `active_support/core_ext/proc.rb`. - Extensions to `Date` -------------------- |