Skip to content

Instantly share code, notes, and snippets.

@justincampbell
Created November 13, 2014 21:00
Show Gist options
  • Save justincampbell/2a39e6791a9fb5a56ee7 to your computer and use it in GitHub Desktop.
Save justincampbell/2a39e6791a9fb5a56ee7 to your computer and use it in GitHub Desktop.
puts "About to define BaseService"
class BaseService
puts "BaseService code running"
def self.clone; puts "clone called"; super; end
def self.dup; puts "dup called"; super; end
end
puts "About to inherit from BaseService"
class MyService < BaseService
puts "MyService code running"
end
class AnotherService
def self.new(*args)
obj = allocate
obj.send(:initialize, *args)
obj
end
def self.allocate
puts "Allocate called"
super
end
def initialize
end
end
AnotherService.new # => #<AnotherService:0x007f959a9d9d10>
# >> About to define BaseService
# >> BaseService code running
# >> About to inherit from BaseService
# >> MyService code running
# >> Allocate called
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment