SHARE
TWEET

Untitled

a guest Jun 24th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def method_missing(id, *args)
  2.     return self.find(Regexp.last_match(1),  args[0]) if id.id2name =~ /find_by_(.+)/
  3.     raise NoMethodError
  4. end
  5.      
  6. # Ensure $~ and friends are nil in case this isn't a fresh REPL.
  7. ''.match /foo/
  8.  
  9. # Make this variable available inside the thread block.
  10. thread_match = nil
  11.  
  12. Thread.new do
  13.   'foo'.match /(foo)/
  14.   thread_match = "In thread: #{$1.inspect}"
  15. end
  16.  
  17. [thread_match, "Global value: #{$1.inspect}"]
  18. #=> ["In thread: "foo"", "Global value: nil"]
  19.      
  20. def foo
  21.   'foo'.match /(foo)/
  22.   p $1
  23. end
  24.  
  25. [foo, $1]
  26. #=> ["foo", nil]
  27.      
  28. irb(main):026:0> thread_match = nil
  29. => nil
  30. irb(main):027:0> Thread.new do
  31. irb(main):028:1* /([[:alpha:]])*/.match('BF92')
  32. irb(main):029:1>   thread_match = "In thread: #{$1.inspect}"
  33. irb(main):030:1> end
  34. => #<Thread:0x00007fbdfc87e080@(irb):27 run>
  35. irb(main):031:0> thread_match
  36. => "In thread: "F""
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top