Skip to content

Instantly share code, notes, and snippets.

@mamantoha
Last active November 23, 2021 13:10
Show Gist options
  • Save mamantoha/4ffa77d0ba4b3b54a8b96f4c922c89bd to your computer and use it in GitHub Desktop.
Save mamantoha/4ffa77d0ba4b3b54a8b96f4c922c89bd to your computer and use it in GitHub Desktop.
Ruby goto

http://patshaughnessy.net/2012/2/29/the-joke-is-on-us-how-ruby-1-9-supports-the-goto-statement

goto.patch:

--- vm_opts.h
+++ vm_opts.h
@@ -48,7 +48,7 @@
 #define OPT_STACK_CACHING            0

 /* misc */
-#define SUPPORT_JOKE                 0
+#define SUPPORT_JOKE                 1

 #ifndef VM_COLLECT_USAGE_DETAILS
 #define VM_COLLECT_USAGE_DETAILS     0
rbenv install -f --patch 2.4.1 < goto.patch

goto.rb:

__label__(:loop)

puts "The Ruby core team is playing a joke on us!"

__goto__(:loop)

puts "This line of code is never reached."
--- vm_opts.h
+++ vm_opts.h
@@ -48,7 +48,7 @@
#define OPT_STACK_CACHING 0
/* misc */
-#define SUPPORT_JOKE 0
+#define SUPPORT_JOKE 1
#ifndef VM_COLLECT_USAGE_DETAILS
#define VM_COLLECT_USAGE_DETAILS 0
__label__(:loop)
puts "The Ruby core team is playing a joke on us!"
__goto__(:loop)
puts "This line of code is never reached."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment