Skip to content

Instantly share code, notes, and snippets.

@samuel02
Created January 15, 2014 11:41
Show Gist options
  • Save samuel02/64867c98df47a14da172 to your computer and use it in GitHub Desktop.
Save samuel02/64867c98df47a14da172 to your computer and use it in GitHub Desktop.
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