SyntaxSuggest.use_prism_parser? [Private]
Tells us if the prism parser is available for use or if we should fallback to ‘Ripper`
Create a new AlternationPatternNode node
Creates an option parser and fills it in with the help info for the command.
Add the –version option to the option parser.
Returns the status of the global “abort on exception” condition.
The default is false.
When set to true, if any thread is aborted by an exception, the raised exception will be re-raised in the main thread.
Can also be specified by the global $DEBUG flag or command line option -d.
See also ::abort_on_exception=.
There is also an instance level method to set this for a specific thread, see abort_on_exception.
When set to true, if any thread is aborted by an exception, the raised exception will be re-raised in the main thread. Returns the new state.
Thread.abort_on_exception = true t1 = Thread.new do puts "In new thread" raise "Exception from thread" end sleep(1) puts "not reached"
This will produce:
In new thread prog.rb:4: Exception from thread (RuntimeError) from prog.rb:2:in `initialize' from prog.rb:2:in `new' from prog.rb:2
See also ::abort_on_exception.
There is also an instance level method to set this for a specific thread, see abort_on_exception=.
Returns the status of the global “report on exception” condition.
The default is true since Ruby 2.5.
All threads created when this flag is true will report a message on $stderr if an exception kills the thread.
Thread.new { 1.times { raise } }
will produce this output on $stderr:
#<Thread:...> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
2: from -e:1:in `block in <main>'
1: from -e:1:in `times'
This is done to catch errors in threads early. In some cases, you might not want this output. There are multiple ways to avoid the extra output:
If the exception is not intended, the best is to fix the cause of the exception so it does not happen anymore.
If the exception is intended, it might be better to rescue it closer to where it is raised rather then let it kill the Thread.
If it is guaranteed the Thread will be joined with Thread#join or Thread#value, then it is safe to disable this report with Thread.current.report_on_exception = false when starting the Thread. However, this might handle the exception much later, or not at all if the Thread is never joined due to the parent thread being blocked, etc.
See also ::report_on_exception=.
There is also an instance level method to set this for a specific thread, see report_on_exception=.
Returns the new state. When set to true, all threads created afterwards will inherit the condition and report a message on $stderr if an exception kills a thread:
Thread.report_on_exception = true t1 = Thread.new do puts "In new thread" raise "Exception from thread" end sleep(1) puts "In the main thread"
This will produce:
In new thread #<Thread:...prog.rb:2> terminated with exception (report_on_exception is true): Traceback (most recent call last): prog.rb:4:in `block in <main>': Exception from thread (RuntimeError) In the main thread
See also ::report_on_exception.
There is also an instance level method to set this for a specific thread, see report_on_exception=.
Returns the status of the thread-local “abort on exception” condition for this thr.
The default is false.
See also abort_on_exception=.
There is also a class level method to set this for all threads, see ::abort_on_exception.
When set to true, if this thr is aborted by an exception, the raised exception will be re-raised in the main thread.
See also abort_on_exception.
There is also a class level method to set this for all threads, see ::abort_on_exception=.
Returns the status of the thread-local “report on exception” condition for this thr.
The default value when creating a Thread is the value of the global flag Thread.report_on_exception.
See also report_on_exception=.
There is also a class level method to set this for all new threads, see ::report_on_exception=.
When set to true, a message is printed on $stderr if an exception kills this thr. See ::report_on_exception for details.
See also report_on_exception.
There is also a class level method to set this for all new threads, see ::report_on_exception=.
Calls the block with each repeated permutation of length n of the elements of self; each permutation is an Array; returns self. The order of the permutations is indeterminate.
When a block and a positive Integer argument n are given, calls the block with each n-tuple repeated permutation of the elements of self. The number of permutations is self.size**n.
n = 1:
a = [0, 1, 2] a.repeated_permutation(1) {|permutation| p permutation }
Output:
[0] [1] [2]
n = 2:
a.repeated_permutation(2) {|permutation| p permutation }
Output:
[0, 0] [0, 1] [0, 2] [1, 0] [1, 1] [1, 2] [2, 0] [2, 1] [2, 2]
If n is zero, calls the block once with an empty Array.
If n is negative, does not call the block:
a.repeated_permutation(-1) {|permutation| fail 'Cannot happen' }
Returns a new Enumerator if no block given:
a = [0, 1, 2] a.repeated_permutation(2) # => #<Enumerator: [0, 1, 2]:permutation(2)>
Using Enumerators, it’s convenient to show the permutations and counts for some values of n:
e = a.repeated_permutation(0) e.size # => 1 e.to_a # => [[]] e = a.repeated_permutation(1) e.size # => 3 e.to_a # => [[0], [1], [2]] e = a.repeated_permutation(2) e.size # => 9 e.to_a # => [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]]
Return the accept character set for all new CGI instances.
Returns the fractional part of the second in range (Rational(0, 1)…Rational(1, 1)):
DateTime.new(2001, 2, 3, 4, 5, 6.5).sec_fraction # => (1/2)
This method is defined for backward compatibility.
Returns the data created by parsing the first line of string or io using the specified options.
Argument string should be a String object; it will be put into a new StringIO object positioned at the beginning.
Argument io should be an IO object that is:
Open for reading; on return, the IO object will be closed.
Positioned at the beginning. To position at the end, for appending, use method CSV.generate. For any other positioning, pass a preset StringIO object instead.
Argument options: see Options for Parsing
headers Without option headers, returns the first row as a new Array.
These examples assume prior execution of:
string = "foo,0\nbar,1\nbaz,2\n" path = 't.csv' File.write(path, string)
Parse the first line from a String object:
CSV.parse_line(string) # => ["foo", "0"]
Parse the first line from a File object:
File.open(path) do |file| CSV.parse_line(file) # => ["foo", "0"] end # => ["foo", "0"]
Returns nil if the argument is an empty String:
CSV.parse_line('') # => nil
headers With {option headers}, returns the first row as a CSV::Row object.
These examples assume prior execution of:
string = "Name,Count\nfoo,0\nbar,1\nbaz,2\n" path = 't.csv' File.write(path, string)
Parse the first line from a String object:
CSV.parse_line(string, headers: true) # => #<CSV::Row "Name":"foo" "Count":"0">
Parse the first line from a File object:
File.open(path) do |file| CSV.parse_line(file, headers: true) end # => #<CSV::Row "Name":"foo" "Count":"0">
Raises an exception if the argument is nil:
# Raises ArgumentError (Cannot parse nil as CSV): CSV.parse_line(nil)
Returns the value that determines whether illegal input is to be handled; used for parsing; see {Option liberal_parsing}:
CSV.new('').liberal_parsing? # => false
Returns the sharing detection flag as a boolean value. It is false (nil) by default.
Sets the sharing detection flag to b.