Skip to content

Instantly share code, notes, and snippets.

@cararemixed
Created March 9, 2020 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cararemixed/84d4629cdbc915f3d1578a9aeaf8843a to your computer and use it in GitHub Desktop.
Save cararemixed/84d4629cdbc915f3d1578a9aeaf8843a to your computer and use it in GitHub Desktop.
Trivial IRBRC
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