mirror of
https://github.com/jbranchaud/til
synced 2026-01-16 21:48:02 +00:00
Compare commits
4 Commits
ab8b7f4eee
...
29dda73025
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29dda73025 | ||
|
|
0c1dd29d8d | ||
|
|
5615da920f | ||
|
|
c60c63f554 |
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1510 TILs and counting..._
|
||||
_1511 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -190,7 +190,7 @@ _1510 TILs and counting..._
|
||||
- [Aliasing An Ansible Host](devops/aliasing-an-ansible-host.md)
|
||||
- [Allow Cross-Origin Requests To Include Cookies](devops/allow-cross-origin-requests-to-include-cookies.md)
|
||||
- [Allow HTTPS Through Your UFW Firewall](devops/allow-https-through-your-ufw-firewall.md)
|
||||
- [Check For Cached Site Assocation File For iOS](devops/check-for-cached-site-association-file-for-ios.md)
|
||||
- [Check For Cached Site Association File For iOS](devops/check-for-cached-site-association-file-for-ios.md)
|
||||
- [Check The Status of All Services](devops/check-the-status-of-all-services.md)
|
||||
- [Check The Syntax Of nginx Files](devops/check-the-syntax-of-nginx-files.md)
|
||||
- [Connect To An RDS PostgreSQL Database](devops/connect-to-an-rds-postgresql-database.md)
|
||||
@@ -723,7 +723,7 @@ _1510 TILs and counting..._
|
||||
- [Check If Clusters Are Upgrade Compatible](postgres/check-if-clusters-are-upgrade-compatible.md)
|
||||
- [Check If The Local Server Is Running](postgres/check-if-the-local-server-is-running.md)
|
||||
- [Check If User Role Exists For Database](postgres/check-if-user-role-exists-for-database.md)
|
||||
- [Check Table For Any Oprhaned Records](postgres/check-table-for-any-orphaned-records.md)
|
||||
- [Check Table For Any Orphaned Records](postgres/check-table-for-any-orphaned-records.md)
|
||||
- [Checking Inequality](postgres/checking-inequality.md)
|
||||
- [Checking The Type Of A Value](postgres/checking-the-type-of-a-value.md)
|
||||
- [Clear The Screen In psql](postgres/clear-the-screen-in-psql.md)
|
||||
@@ -1249,6 +1249,7 @@ _1510 TILs and counting..._
|
||||
- [Navigate Back In The Browser With Capybara](ruby/navigate-back-in-the-browser-with-capybara.md)
|
||||
- [Next And Previous Floats](ruby/next-and-previous-floats.md)
|
||||
- [Or Operator Precedence](ruby/or-operator-precedence.md)
|
||||
- [Output Bytecode For A Ruby Program](ruby/output-bytecode-for-a-ruby-program.md)
|
||||
- [Override The Initial Sequence Value](ruby/override-the-initial-sequence-value.md)
|
||||
- [Parallel Bundle Install](ruby/parallel-bundle-install.md)
|
||||
- [Parse JSON Into An OpenStruct](ruby/parse-json-into-an-open-struct.md)
|
||||
|
||||
42
ruby/output-bytecode-for-a-ruby-program.md
Normal file
42
ruby/output-bytecode-for-a-ruby-program.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# Output Bytecode For A Ruby Program
|
||||
|
||||
The `ruby` CLI comes with a flag to dump the disassembled YARV bytecode for the
|
||||
given Ruby program. This can be a fun way to explore how a Ruby program is
|
||||
interpreted under the hood.
|
||||
|
||||
Aaron Patterson demoed this behavior during his RubyConf 2024 talk.
|
||||
|
||||
Pass the `--dump` flag with `insns` along with either the path to your file or
|
||||
an inline bit of Ruby.
|
||||
|
||||
Here is a really basic example:
|
||||
|
||||
```bash
|
||||
❯ ruby --dump=insns -e '2 + 3'
|
||||
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,5)> (catch: false)
|
||||
0000 putobject 2 ( 1)[Li]
|
||||
0002 putobject 3
|
||||
0004 opt_plus <calldata!mid:+, argc:1, ARGS_SIMPLE>[CcCr]
|
||||
0006 leave
|
||||
```
|
||||
|
||||
And another quite basic example, but with local variables this time:
|
||||
|
||||
```bash
|
||||
❯ ruby --dump=insns -e 'x = 2; y = 3; x + y'
|
||||
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,19)> (catch: false)
|
||||
local table (size: 2, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
|
||||
[ 2] x@0 [ 1] y@1
|
||||
0000 putobject 2 ( 1)[Li]
|
||||
0002 setlocal_WC_0 x@0
|
||||
0004 putobject 3
|
||||
0006 setlocal_WC_0 y@1
|
||||
0008 getlocal_WC_0 x@0
|
||||
0010 getlocal_WC_0 y@1
|
||||
0012 opt_plus <calldata!mid:+, argc:1, ARGS_SIMPLE>[CcCr]
|
||||
0014 leave
|
||||
```
|
||||
|
||||
If you want to dig in to how to read everything that is going on in these
|
||||
outputs, I'd recommend checking out this [Advent of YARV
|
||||
series](https://kddnewton.com/2022/11/30/advent-of-yarv-part-0.html)
|
||||
Reference in New Issue
Block a user