Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def method_missing(id, *args)
- return self.find(Regexp.last_match(1), args[0]) if id.id2name =~ /find_by_(.+)/
- raise NoMethodError
- end
- # Ensure $~ and friends are nil in case this isn't a fresh REPL.
- ''.match /foo/
- # Make this variable available inside the thread block.
- thread_match = nil
- Thread.new do
- 'foo'.match /(foo)/
- thread_match = "In thread: #{$1.inspect}"
- end
- [thread_match, "Global value: #{$1.inspect}"]
- #=> ["In thread: "foo"", "Global value: nil"]
- def foo
- 'foo'.match /(foo)/
- p $1
- end
- [foo, $1]
- #=> ["foo", nil]
- irb(main):026:0> thread_match = nil
- => nil
- irb(main):027:0> Thread.new do
- irb(main):028:1* /([[:alpha:]])*/.match('BF92')
- irb(main):029:1> thread_match = "In thread: #{$1.inspect}"
- irb(main):030:1> end
- => #<Thread:0x00007fbdfc87e080@(irb):27 run>
- irb(main):031:0> thread_match
- => "In thread: "F""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement