Skip to content

Instantly share code, notes, and snippets.

@r3nya
Last active December 15, 2015 14:49
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 r3nya/5277786 to your computer and use it in GitHub Desktop.
Save r3nya/5277786 to your computer and use it in GitHub Desktop.
Мой пример синглтона на Ruby, надеюсь он правильный. :)
# encoding: UTF-8
require 'singleton'
class Cats
include Singleton
def initialize
@cat = { name: 'Alice', sex: 'F' }
end
def ask(msg)
puts msg
end
end
kitty = Cats.instance
puts "У меня есть кошка. Её зовут #{kitty.instance_eval { @cat[:name]} }"
print "Она может кричать: "
kitty.ask('мяяяуууу!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment