Skip to content

Instantly share code, notes, and snippets.

@samuel02
Created January 15, 2014 11:41
inheritance with blocks
class A
def initialize
@logger = Rails.logger || Logger.new(STDOUT)
end
def foo
begin
yield
rescue StandardError => e
@logger.error e
raise StandardError
end
end
end
class B < A
def foo
super do
f = File.open('baz.txt', 'w')
f.write('lorem')
f.close
end
end
end
class C < A
def foo
super do
...
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment