Skip to content

Instantly share code, notes, and snippets.

View yuki24's full-sized avatar
🔢
NaN :trollface:

Yuki Nishijima yuki24

🔢
NaN :trollface:
View GitHub Profile
@yuki24
yuki24 / routes_ast.rb
Created July 22, 2019 01:19
Rails routes AST access
#
# Run this with `rails runner route_ast.rb`
#
Rails.application.routes.routes.each do |route|
ast = route.ast
# do stuff with AST...
end
@yuki24
yuki24 / colon_equal.rb
Created April 23, 2020 22:16
One-liner method definition in Ruby
module OneLinerExamples
# https://github.com/rack/rack/blob/f9ad97fd/lib/rack/request.rb#L150-L155
def body := get_header(RACK_INPUT)
def script_name := get_header(SCRIPT_NAME).to_s
def script_name=(s) := set_header(SCRIPT_NAME, s.to_s)
def path_info := get_header(PATH_INFO).to_s
def path_info=(s) := set_header(PATH_INFO, s.to_s)
# https://github.com/rack/rack/blob/f9ad97fd/lib/rack/response.rb#L126-L129