Skip to content

Instantly share code, notes, and snippets.

@AnatoliiD
Last active October 22, 2015 08:26
Show Gist options
  • Save AnatoliiD/7d52f708dbe7aaae0631 to your computer and use it in GitHub Desktop.
Save AnatoliiD/7d52f708dbe7aaae0631 to your computer and use it in GitHub Desktop.
yield duplications
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