This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative './event_emitter_core' | |
# class for users | |
class User | |
attr_reader :first_name | |
def initialize(first_name) | |
@first_name = first_name | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative './event_emitter_core' | |
class EventEmitter | |
include EventEmitterCore | |
end | |
event_emitter = EventEmitter.new | |
# the code should be executed when event will be triggered | |
ring_bell = lambda do |event_name, object| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the module can be included to any class | |
module EventEmitterCore | |
# turn on the event | |
# @param event_name [String, Symbol] | |
def on(event_name) | |
events[event_name.to_sym] ||= [] | |
end | |
# turn off the event | |
# @param event_name [String, Symbol] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tags | |
Hash: | |
Hash<KeyType, ValueType> | |
Hash{KeyTypes=>ValueTypes} | |
how to doc hash in arguments | |
<% | |
# @param [Hash] opts the options to create a message with. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$MY_FILE_PATH = File.expand_path(File.dirname(__FILE__)) | |
content = File.open("#{$MY_FILE_PATH}/#{__FILE__}").read | |
puts content | |
puts 'end of script' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------ | |
******************** | |
CONFIDENT RUBY | |
******************** | |
------------------------------ | |
каждый метод может состоять максимум из 4 частей | |
1 Collecting input | |
2 Performing work | |
3 Delivering output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'time' | |
# thread pool class | |
# it takes pool size | |
class ThreadPool | |
attr_reader :result, :number, :size | |
def initialize(size) | |
@finish = false | |
@result = nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'time' | |
module HashGenerator | |
# calculating hash for string "#{string}#{number}" | |
def self.call(string, number) | |
# for macOS | |
return `echo '#{string}#{number}' | sha2 -256` | |
.gsub('SHA-256 ((null)) = ', '') | |
.gsub(/\n/, '') | |
# for Linux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# thread pool class | |
class ThreadPool | |
def initialize(size) | |
@size = size | |
@jobs = Queue.new | |
@pool = Array.new(@size) do |i| | |
Thread.new do | |
Thread.current[:id] = i | |
catch(:exit) do | |
loop do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'socket' | |
# run on localhost:3000 | |
server = TCPServer.new('localhost', 3000) | |
loop do | |
Thread.start(server.accept) do |socket| | |
request = socket.gets | |
method, path = request.split | |
sleep_time = rand(5) |
NewerOlder