Skip to content

Instantly share code, notes, and snippets.

@packrat386
Created May 7, 2023 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save packrat386/3f596fa472201c1ae04bf587c4fd9b13 to your computer and use it in GitHub Desktop.
Save packrat386/3f596fa472201c1ae04bf587c4fd9b13 to your computer and use it in GitHub Desktop.
class ClassMethodClient
def self.get_thing
"thing"
end
def self.put_thing(thing)
nil
end
end
puts "get: #{ClassMethodClient.get_thing}"
puts "put: #{ClassMethodClient.put_thing("other")}"
puts "what does this do: #{ClassMethodClient.new}"
puts ClassMethodClient.is_a? Class # true
puts ClassMethodClient.is_a? Object # true
ObjectClient = Class.new do
def get_thing
"thing"
end
def put_thing(thing)
nil
end
end.new
puts "get: #{ObjectClient.get_thing}"
puts "put: #{ObjectClient.put_thing("other")}"
begin
puts "what does this do: #{ObjectClient.new}"
rescue => e
puts "can't ObjectClient.new: #{e.message}"
end
puts ObjectClient.is_a? Class # false
puts ObjectClient.is_a? Object # true
require 'singleton'
class SingletonClient
include Singleton
def get_thing
"thing"
end
def put_thing(thing)
nil
end
end
begin
puts "what does this do: #{SingletonClient.new}"
rescue => e
puts "can't SingletonClient.new: #{e.message}"
end
puts SingletonClient.is_a? Class # true
puts SingletonClient.is_a? Object # true
puts "get: #{SingletonClient.instance.get_thing}"
puts "put: #{SingletonClient.instance.put_thing("other")}"
begin
puts "what does this do: #{SingletonClient.instance.new}"
rescue => e
puts "can't SingletonClient.instance.new: #{e.message}"
end
puts SingletonClient.instance.is_a? Class # false
puts SingletonClient.instance.is_a? Object # true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment