Last active
December 18, 2015 16:59
-
-
Save fujimura/5815088 to your computer and use it in GitHub Desktop.
Object#pipe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
def pipe | |
yield self | |
end | |
end | |
# From https://github.com/rspec/rspec-rails/pull/766/files | |
# Without Object#pipe | |
types = begin | |
dirs = Dir['./spec/**/*_spec.rb']. | |
map { |f| f.sub(/^\.\/(spec\/\w+)\/.*/, '\\1') }. | |
uniq. | |
select { |f| File.directory?(f) } | |
Hash[dirs.map { |d| [d.split('/').last, d] }] | |
end | |
# With Object#pipe | |
types = Dir['./spec/**/*_spec.rb']. | |
map { |f| f.sub(/^\.\/(spec\/\w+)\/.*/, '\\1') }. | |
uniq. | |
select { |f| File.directory?(f) }. | |
map { |d| [d.split('/').last, d] }. | |
pipe { |type_and_dirs| Hash[type_and_dirs] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment