クラスメソッドを定義するときのコードで出てくる class << self
class Foo
class << self
def bar
:bar
end
end
end| require "prism" | |
| code = <<~STR | |
| def foo | |
| 1+2 | |
| end | |
| STR | |
| p Prism.parse(code) | |
| #=> #<Prism::ParseResult:0x0000000101132048 @value=@ ProgramNode (location: (1,0)-(3,3)) ... |
クラスメソッドを定義するときのコードで出てくる 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)", |