Skip to content

Instantly share code, notes, and snippets.

クラスメソッドを定義するときのコードで出てくる class << self

class Foo
  class << self
    def bar
      :bar
    end
  end
end

igaigaのペアプロ屋 🛍️

  • Rails関連の話題についてなんでもご相談に乗ります

想定対象者

  • Railsエンジニア
    • 初学者さん: Railsの基礎から実践まで話題を取りそろえています
    • 中級者さん: Railsの実践や発展的な話題を用意しています
  • ベテランさん: 設計や課題解決などご相談にのります
# $ pip install openai llama_index pypdf
from llama_index import GPTVectorStoreIndex, SimpleDirectoryReader
import openai
# APIキーを取得: https://platform.openai.com/account/api-keys
openai.api_key = "API KEYを書く"
# dataフォルダ以下のPDFファイルの読み込み
documents = SimpleDirectoryReader("data").load_data()
# https://github.com/st0012/ruby_tracer
Tracer.new(:exception) {}
Tracer.new(:exception).trace {}
Tracer.new(:exception).config(a: true, b: 1, ...).trace {}
Tracer.new(:exception, config_a: true, config_b: 1, ...).trace {}
# The method name "trace" is nice, but maybe a better name?
# "Tracer#trace" seems redundant.
require "typeprof"
target_code = <<~STR
result = []
a = [1,2,3].each do |x|
result << x * 2
end
p a
p result
STR
@igaiga
igaiga / tp0111.rb
Last active January 11, 2023 01:56
require "typeprof"
target_code = <<~STR
result = []
a = [1,2,3].each do |x|
result << x * 2
end
p a
p result
STR
class ParentController
before_action :something_method
private
def something_method
"Parent"
end
end
class ChildController < ParentController
# before_actionは書かない
app_routes = Rails.application.routes.routes
ActionDispatch::Routing::RoutesInspector.new(app_routes).send(:collect_routes, app_routes)
#=>
[{:name=>"books",
:verb=>"GET",
:path=>"/books(.:format)",
:reqs=>"books#index"},
{:name=>"",
:verb=>"POST",
:path=>"/books(.:format)",

Unicorn

起動設定ファイルを /var/tdiary/tdiary-core/unicorn.conf へ配置

/var/tdiary/tdiary-core/unicorn.conf

worker_processes 4
listen 8080, :tcp_nopush => true
### Thread.current is fiber local
f = Fiber.new do
Thread.current[:foo] = 0
loop do
Fiber.yield(Thread.current[:foo])
Thread.current[:foo] += 1
end
end
f2 = Fiber.new do