Sha256: 9358005fd613def4e238feb6a4cf22137ea658158725e0d5953e07b658339cd4
Contents?: true
Size: 592 Bytes
Versions: 2
Compression:
Stored size: 592 Bytes
Contents
class Object # Yields <code>x</code> to the block, and then returns <code>x</code>. # The primary purpose of this method is to "tap into" a method chain, # in order to perform operations on intermediate results within the chain. # # (1..10).tap { |x| puts "original: #{x.inspect}" }.to_a. # tap { |x| puts "array: #{x.inspect}" }. # select { |x| x%2 == 0 }. # tap { |x| puts "evens: #{x.inspect}" }. # map { |x| x*x }. # tap { |x| puts "squares: #{x.inspect}" } def tap yield self self end unless Object.respond_to?(:tap) end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
activesupport-3.0.pre | lib/active_support/core_ext/object/tap.rb |
recliner-0.0.1 | vendor/activesupport/lib/active_support/core_ext/object/tap.rb |