Last active
October 22, 2015 08:26
-
-
Save AnatoliiD/7d52f708dbe7aaae0631 to your computer and use it in GitHub Desktop.
yield duplications
This file contains 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 Before | |
class << self | |
def method1 | |
puts 'first duplication' | |
puts 'i am uniq for method 1' | |
puts 'second duplication' | |
end | |
def method2 | |
puts 'first duplication' | |
puts 'i am uniq for method 2' | |
puts 'second duplication' | |
end | |
end | |
end | |
class After | |
class << self | |
def method1 | |
dups do | |
puts 'i am uniq for method 1' | |
end | |
end | |
def method2 | |
dups do | |
puts 'i am uniq for method 2' | |
end | |
end | |
def dups | |
puts 'first duplication' | |
yield | |
puts 'second duplication' | |
end | |
end | |
end | |
puts "Before:" | |
Before.method1 | |
puts | |
Before.method2 | |
puts '*******' | |
puts "After:" | |
After.method1 | |
puts | |
After.method2 | |
# | |
# Before: | |
# first duplication | |
# i am uniq for method 1 | |
# second duplication | |
# | |
# first duplication | |
# i am uniq for method 2 | |
# second duplication | |
# ******* | |
# After: | |
# first duplication | |
# i am uniq for method 1 | |
# second duplication | |
# | |
# first duplication | |
# i am uniq for method 2 | |
# second duplication |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment