Skip to content

Instantly share code, notes, and snippets.

@jkeam
Created April 14, 2022 20:02
Show Gist options
  • Save jkeam/ddc5fca16816be645b2c73b88c29b5ee to your computer and use it in GitHub Desktop.
Save jkeam/ddc5fca16816be645b2c73b88c29b5ee to your computer and use it in GitHub Desktop.
Quick demonstration on how to create temporary anonymous classes as well as how to extend them
# encoding: UTF-8
# frozen_string_literal: true
Metric = Class.new do
def destroy
puts 'Metric destroyed'
end
end
MetricWithFiber = Class.new(Metric) do
def destroy
super
puts 'MetricWithFiber destroyed'
end
end
instance = MetricWithFiber.new
instance.destroy
@jkeam
Copy link
Author

jkeam commented Apr 14, 2022

Running this:

ruby ./anonymous_class.rb

produces:

Metric destroyed
MetricWithFiber destroyed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment