A ridiculously comprehensive 'cheat sheet' created by Ryan Davis covering syntax rules, reserved words, regular expression terminology, class and method definitions, predefined variables and constants, control and logic expressions and formations, exceptions, the standard library, and a whole ton of useful stuff. General overview of methods and syntax for the Ruby programming language. General overview of methods and syntax for the Ruby programming language. Your Favourite Cheat Sheets; Your Messages. This is a draft cheat sheet. It is a work in progress and is not finished yet. Primary resource for Ruby. Ruby BASICS Cheat Sheet. Information Types: Ruby has a few different types of information types; below are some examples of what defines each and how they're properly formatted. Strings: Anything within quotes are considered strings. Numbers: More commonly referred. Reverse Shell Cheat Sheet If you’re lucky enough to find a command execution vulnerability during a penetration test, pretty soon afterwards you’ll probably want an interactive shell. If it’s not possible to add a new account / SSH key /.rhosts file and just log in, your next step is likely to be either trowing back a reverse shell.
This document is all about deciphering behavior of Ruby code using nothing but Ruby code. I recommend you get familiar with a debugger like pry-debugger, this doc doesn’t go into debuggers because they’re not always available.
Many of these techniques are pulled from my first popular talk Dissecting Ruby with Ruby.
This page is open source and a living document, send suggestions in PR form to my blog on GitHub.
Unless otherwise stated, all techniques work for the last major release of Ruby.
Figure out where a method was defined
This method was defined on line 14
of the file active_support/core_ext/object/blank.rb
.
Opening a dependency from a project
This will open the version of active_support
you have in your Gemfile.lock
. From here you can add debugging statements.
This command will use the value in your EDITOR
environment variable. The default is vi or something. You can set this in your .bashrc
file. For example I use Sublime text and have this in my .bashrc
Google for the appropriate invocation for your editor.
If you close the file accidentally you can use gem pristine
which is discussed below.
See where an object was created
You can use object space to see where a constant or an object was created.
Since the invocation to get the file and line number is so long, I added a helper method sup
. Make sure tracing is started early as possible, I usually put this code in the top of my Gemfile. Remove this code when you’re not debugging, tracing allocations has a performance impact.
If you find yourself on a remote machine without access to an editor you can inject this into a Gemfile in a few lines of bash
Thanks to Aaron’s “I need to find where this object came from”.
Figuring out how a method was called
To generate a backtrace without raising an exception use the caller
method like:
Now when you generate a request you’ll get a backtrace like:
Ugh, long ugly backtrace. What does it mean? The top line is the last method that was run before our, puts caller
was called. In this case
This was called from the projects_controller
line 18, in the new
method in my app. We can trace this back all the way to the beginning of the request by looking at the first line
This is where Puma instantiated the request.
If you work from the bottom of the backtrace and go up, you can see exactly how Puma turns a request into code.
Find which method Super is Calling
Let’s say you have code that calls super
you can find where that method is defined like this:
I love this one since I proposed the method 😉. You can read more about super_method
here: Debugging Super methods in Ruby 2.2+.
List all methods on an object

Get instance method location without an instance
Introspect method arguments
Now you can see all available keyword arguments.

See where an argument is mutated
Often times, I’ll instantiate a variable
But later I’ll find it was changed, but I don’t know where:
You can see where the value of an object was modified by first freeze
-ing the object:

Then later if other code modifies the object, an error will be raised:
There are some caveats: In this example the hash is frozen, but the keys and values are not. If you try to modify a key or value, no exception will be raised. If you’re trying to freeze a complex object such as a Hash, you’ll need to deep freeze it. This technique also won’t work for cases where a variable is assigned instead of mutated.
Originally on my “missing pieces” list, TLo documented it An object is being mutated but I don’t know where.
Un-debug a gem
If you’ve opened a gem and added debug statements, but forget to remove them before closing the file: you’ll get those debug statements every time you run your program. To reset every gem to its original state you can use gem pristine
. For example to reset Active Support:
To reset ALL gems you can run:
Note: this may take a LONG time, especially if you’ve got gems with c-extensions.
Missing Pieces Wish List
Warning: These things don’t exist, but I wish they did. Don’t try to use them, they won’t work.

Here’s a list of things I want to do from time to time, but haven’t found a way to yet. Some of these might not be possible due to limitations in the VM. When a “missing piece” is found it is removed from this section and given it’s own heading above.
- Find where a variable is over-written with a different value. While we can use the
freeze
trick to see where a value is modified, we won’t see when it is replaced.
Not debugging
These are a few tricks that aren’t debugging related, but I’ve found helpful for understanding how the interpreter works.

Disassemble Ruby code:
Sql Syntax Cheat Sheet
Generates something like this:
Keep Reading 🚀
Ruby Syntax Cheat Sheet Cheat
Migrating a Ruby Library from TravisCI to CircleCI
TravisCI.org is dead. Long live the new CI! TravisCI.org was THE way to run CI for an open source Ruby library. It was so easy that it was seemingly effortless. Even better, it was free. Since the slow-motion collapse of the product, developers have been pushed to other CI providers. I was recently tasked with transferring CI away from Travis for my library derailed_benchmarks and chose CircleCI. This post is a little about why I chose CircleCI, a little about how the transition worked, and a little about nostalgia.
Squash Unexpected-End errors with syntax_search
Have you ever hit an error that you just plain hate? Back in 2006, I was learning to program Ruby and following an example from a book. I typed in what I saw, hit enter, and ran into a supremely frustrating error message:
Triage with Me - 11 issues & 2 PRs in 1.5 hours
Contributing to open-source can be intimidating, especially when you’re getting started. In this post and video series, join me as I triage 11 issues on a repo that I didn’t create and don’t have much experience with. Dinot font free download mac.
The Life-Changing Magic of Tidying Ruby Object Allocations
Your app is slow. It does not spark joy. This post will show you how to use memory allocation profiling tools to discover performance hotspots, even when they’re coming from inside a library. Amplitube free download mac. We will use this technique with a real-world application to identify a piece of optimizable code in Active Record that ultimately leads to a patch with a substantial impact on page speed.
A Fast Car Needs Good Brakes: How We Added Client Rate Throttling to the Platform API Gem
When API requests are made one-after-the-other they’ll quickly hit rate limits and when that happens:
Welcome to this socat tutorial. Socat is a network utility similar to netcat. Socat supports ipv6 and ssl and is available for both windows and linux. The first thing you will notice with this tool is that it has a different syntax on what you are used to with netcat or other standard unix tools.
You have to provide both addresses in order for it to work, now these addresses look like this:
Let’s get started with some examples. First I want to show you how you can get the same functionality as with netcat.
Now we can go beyond netcat with some ssl examples, but first we need to generate a ssl cert for the server.
Generate a SSL cert
Usenet download client mac. openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout cert.key
SSL server
SSL client
Both addresses don’t have to use the same protocol, so you can do “ssl server -> non-ssl server”. You should also check out the options that you can apply, for example you can use fork to tell socat to listen and handle multiple clients.
Finally if you are tunneling a connection between servers using socat you can use the -v option to print all the traffic to stdout.
I hope you enjoyed this quick socat tutorial. If you want to learn more, check out the socat man page, section “ADDRESS TYPES” or the online documentation.
