Grow.rb/Entaku.rb/Rubygemsコードリーディング部ではアンチハラスメントポリシーを定めています。
以下の内容について合意・遵守いただけない場合、イベントへの参加をお断りする・イベントからの退出をお願いする場合がございますので予めご了承ください。
当ポリシーは参加者の皆さんにイベントを最大限に楽しんでいただくために策定されました。
# frozen_string_literal: true | |
source "https://rubygems.org" | |
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } | |
gem "rails" | |
gem "sqlite3" | |
gem "jbuilder" | |
gem "active_model_serializers" |
class WithEffect | |
def initialize | |
@list = ["Foo", "Bar", 42, "Baz"] | |
end | |
def process_item(item) | |
throw(:item_not_string, 42) unless item.is_a?(String) | |
puts item | |
end |
module EachWithEffect | |
DEFAULT = Object.new.freeze | |
def each_with_effect(effect_handlers = {}, &block) | |
effect = catch(:effect) do | |
block.call(self.peek) | |
end | |
if effect | |
handler = effect_handlers.find{ |k, v| k === effect }&.last || effect_handlers.fetch(DEFAULT) | |
alternative = handler.call(effect) if handler |
class Module | |
def define_mixable_method(name:, calls:, main:) | |
define_method(name) do |&block| | |
method_candidates = calls.map {|name| method(name) } | |
block.call(main, method_candidates).each do |m| | |
m.call | |
end | |
end | |
end | |
end |
module Kernel | |
def ice(key, value, on: Object) | |
if on.instance_methods.include?(key.to_sym) | |
prev = on.instance_method(key) | |
on.define_method key do | |
on.remove_method key | |
on.define_method(key, prev) | |
return value | |
end | |
else |
MAPPING = { | |
a: 1, | |
b: 2, | |
c: 3, | |
d: 4, | |
e: 5, | |
f: 6, | |
}.freeze | |
def method1(key) |
class Hash | |
def transform(&block) | |
new_hash = {} | |
each_pair do |key, value| | |
rtn = block.call(key, value) | |
case rtn | |
in nil | true then new_hash[key] = value | |
in false then next | |
in Array[[_, _], *] | |
rtn.each do |k, v| |
def self.included(base) | |
base.instance_variable_set(:@count, 0) unless base.instance_variable_defined?(:@count) | |
base.instance_variable_set(:@count, base.instance_variable_get(:@count) + 1) | |
puts base.name if base.instance_variable_get(:@count) > 1 | |
end |
class MyStringScanner | |
class ScanError < StandardError; end | |
attr_reader :string, :captures | |
attr_accessor :pos | |
def initialize(string, _obsolete = false, fixed_anchor: false) | |
@string = string | |
@fixed_anchor = fixed_anchor | |
@pos = 0 | |
@previous_pos = 0 |