Skip to content

Instantly share code, notes, and snippets.

@hoff2
Created October 28, 2011 19:13
Show Gist options
  • Save hoff2/1323195 to your computer and use it in GitHub Desktop.
Save hoff2/1323195 to your computer and use it in GitHub Desktop.
overriding #call in the singleton class of a Proc, a bad idea in the first place, but also:
ruby-1.9.2-p290 :030 > a = proc{'eh'}
=> #<Proc:0x000001009ac850@(irb):30>
ruby-1.9.2-p290 :031 > a.()
=> "eh"
ruby-1.9.2-p290 :032 > a[]
=> "eh"
ruby-1.9.2-p290 :033 > a.call
=> "eh"
ruby-1.9.2-p290 :034 > def a.call; super + '?'; end
=> nil
ruby-1.9.2-p290 :035 > a.()
=> "eh?"
ruby-1.9.2-p290 :036 > a[]
=> "eh"
ruby-1.9.2-p290 :037 > a.call
=> "eh?"
@hoff2
Copy link
Author

hoff2 commented Nov 8, 2011

Ideas:

  • try something similar with a lambda

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