クラスメソッドを定義するときのコードで出てくる class << self
class Foo
class << self
def bar
:bar
end
end
end
クラスメソッドを定義するときのコードで出てくる class << self
class Foo
class << self
def bar
:bar
end
end
end
# $ 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 |
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)", |
### 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 |