Skip to content

Instantly share code, notes, and snippets.

@jinhucheung
Last active December 27, 2018 13:27
Show Gist options
  • Select an option

  • Save jinhucheung/dcba2ee5fd440990e43786ca5284722e to your computer and use it in GitHub Desktop.

Select an option

Save jinhucheung/dcba2ee5fd440990e43786ca5284722e to your computer and use it in GitHub Desktop.
Call method of a Ruby Singleton without instance
require 'singleton'
require 'forwardable'
class Postman
include Singleton
class << self
extend Forwardable
def_delegators :instance, :post, :delete
end
def post
puts 'post!'
end
def delete
puts 'delete!'
end
end
require 'singleton'
class Postman
include Singleton
class << self
delegate :post, :delete, to: :instance
end
def post
puts 'post!'
end
def delete
puts 'delete!'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment