|
module EnumerableExtensions
|
|
refine Array do
|
|
def second
|
|
self[1]
|
|
end
|
|
|
|
def middle
|
|
self[size / 2]
|
|
end
|
|
end
|
|
end
|
|
|
|
using EnumerableExtensions
|
|
|
|
class Singleton
|
|
private_class_method :new
|
|
|
|
@instance = nil
|
|
|
|
def self.instance
|
|
@instance ||= new
|
|
end
|
|
end
|
|
|
|
module_function
|
|
|
|
def log(level, message)
|
|
warn "[#{level.upcase}] #{message}"
|
|
end
|
|
|
|
require "ostruct"
|
|
require "set"
|
|
require "delegate"
|
|
|
|
Point = Struct.new(:x, :y, keyword_init: true)
|
|
p = Point.new(x: 10, y: 20)
|
|
|
|
class Stack
|
|
include Enumerable
|
|
|
|
def initialize
|
|
@items = []
|
|
end
|
|
|
|
def push(item)
|
|
@items.push(item)
|
|
end
|
|
|
|
def pop
|
|
@items.pop
|
|
end
|
|
|
|
def each(&block)
|
|
@items.each(&block)
|
|
end
|
|
end
|
|
|
|
s = Stack.new
|
|
s.push(1)
|
|
s.push(2)
|
|
s.each { |i| puts i }
|
|
|
|
$global_count = 0
|
|
DEFAULT_TIMEOUT = 30
|
|
|
|
puts "Global: #{$global_count}, Timeout: #{DEFAULT_TIMEOUT}"
|