Created
March 9, 2020 23:33
-
-
Save cararemixed/84d4629cdbc915f3d1578a9aeaf8843a to your computer and use it in GitHub Desktop.
Trivial IRBRC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if Object.const_defined?("Rails") | |
def r(model) | |
model.connection; | |
model.columns.map {|col| | |
[col.name, col.type] | |
}.to_h | |
end | |
def rp(model, filter = nil) | |
pp case filter | |
when nil | |
r(model) | |
when Symbol | |
r(model).select {|_, type| type == filter } | |
else | |
r(model).select {|col, _| col =~ filter } | |
end | |
nil | |
end | |
puts <<~NFO | |
Rails Shortcuts: r(model), rp(model, filter?) | |
NFO | |
end | |
def i(obj) | |
pp obj; nil | |
end | |
def m(obj, pattern = nil) | |
methods = obj.methods.sort | |
(pattern ? methods.grep(pattern) : methods) - Object.methods | |
end | |
def im(obj, pattern = nil) | |
i(m(obj, pattern)) | |
end | |
puts <<~NFO | |
Shortcuts: i(obj), m(obj, pattern?), im(obj, pattern?) | |
NFO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment