Skip to content

Instantly share code, notes, and snippets.

@inglesp
Created October 7, 2015 10:15
Show Gist options
  • Save inglesp/c51900daed682699e29d to your computer and use it in GitHub Desktop.
Save inglesp/c51900daed682699e29d to your computer and use it in GitHub Desktop.
NIGHTMARES
$ irb
2.2.2 :001 > def a l = def b; <<-NIGHTMARES; end; puts send l; end
2.2.2 :002"> 😱😱😱
2.2.2 :003"> NIGHTMARES
=> :a
2.2.2 :004 > a
😱😱😱
@tomclose
Copy link

tomclose commented Oct 7, 2015

I think <<-EOF means 'everything on the next line until you get the line EOF'. So that reduces to

def b
   "ghost faces here"
end

Then a is just a function with a default value that is a symbol representing a function defined on the kernel:

def a(l = :b)
   puts send l
end

Test:

def f; 7; end

a(:f) #=> 7

@inglesp
Copy link
Author

inglesp commented Oct 7, 2015

Aha, thanks. I was baffled by what the heredoc was doing, and I'd forgotten that you don't need parentheses around a function's parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment