Returns the fractional part of the second.
DateTime.new(2001,2,3,4,5,6.5).sec_fraction #=> (1/2)
Returns additional info.
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=
.
Specifies a Proc
object proc
to determine if a character in the user’s input is escaped. It should take the user’s input and the index of the character in question as input, and return a boolean (true if the specified character is escaped).
Readline
will only call this proc with characters specified in completer_quote_characters
, to discover if they indicate the end of a quoted argument, or characters specified in completer_word_break_characters
, to discover if they indicate a break between arguments.
If completer_quote_characters
is not set, or if the user input doesn’t contain one of the completer_quote_characters
or a ++ character, Readline
will not attempt to use this proc at all.
Raises ArgumentError
if proc
does not respond to the call method.
Returns the quoting detection Proc
object.
Writes out text, substituting special characters beforehand. out
A String
, IO
, or any other object supporting <<( String
) input
the text to substitute and the write out
z=utf8.unpack("U*") ascOut="" z.each{|r| if r < 0x100 ascOut.concat(r.chr) else ascOut.concat(sprintf("&#x%x;", r)) end } puts ascOut
Starts tracing object allocations.
Returns the Ruby source filename and line number containing first definition of constant specified. If the named constant is not found, nil
is returned. If the constant is found, but its source location can not be extracted (constant is defined in C code), empty array is returned.
inherit specifies whether to lookup in mod.ancestors
(true
by default).
# test.rb: class A C1 = 1 end module M C2 = 2 end class B < A include M C3 = 3 end class A # continuation of A definition end p B.const_source_location('C3') # => ["test.rb", 11] p B.const_source_location('C2') # => ["test.rb", 6] p B.const_source_location('C1') # => ["test.rb", 2] p B.const_source_location('C2', false) # => nil -- don't lookup in ancestors p Object.const_source_location('B') # => ["test.rb", 9] p Object.const_source_location('A') # => ["test.rb", 1] -- note it is first entry, not "continuation" p B.const_source_location('A') # => ["test.rb", 1] -- because Object is in ancestors p M.const_source_location('A') # => ["test.rb", 1] -- Object is not ancestor, but additionally checked for modules p Object.const_source_location('A::C1') # => ["test.rb", 2] -- nesting is supported p Object.const_source_location('String') # => [] -- constant is defined in C code
Makes the set compare its elements by their identity and returns self. This method may not be supported by all subclasses of Set
.
Returns true if the set will compare its elements by their identity. Also see Set#compare_by_identity
.
Initialize WIN32OLE
object(ActiveX Control) by calling IPersistMemory::InitNew.
Before calling OLE method, some kind of the ActiveX controls created with MFC should be initialized by calling IPersistXXX::InitNew.
If and only if you received the exception “HRESULT error code: 0x8000ffff catastrophic failure”, try this method before invoking any ole_method.
obj = WIN32OLE.new("ProgID_or_GUID_of_ActiveX_Control") obj.ole_activex_initialize obj.method(...)
Makes hsh compare its keys by their identity, i.e. it will consider exact same objects as same keys.
h1 = { "a" => 100, "b" => 200, :c => "c" } h1["a"] #=> 100 h1.compare_by_identity h1.compare_by_identity? #=> true h1["a".dup] #=> nil # different objects. h1[:c] #=> "c" # same symbols are all same.
Returns true
if hsh will compare its keys by their identity. Also see Hash#compare_by_identity
.
Returns the class for the given object
.
class A def foo ObjectSpace::trace_object_allocations do obj = Object.new p "#{ObjectSpace::allocation_class_path(obj)}" end end end A.new.foo #=> "Class"
See ::trace_object_allocations
for more information and examples.
Specifies a character to be appended on completion. Nothing will be appended if an empty string (“”) or nil is specified.
For example:
require "readline" Readline.readline("> ", true) Readline.completion_append_character = " "
Result:
> Input "/var/li". > /var/li Press TAB key. > /var/lib Completes "b" and appends " ". So, you can continuously input "/usr". > /var/lib /usr
NOTE: Only one character can be specified. When “string” is specified, sets only “s” that is the first.
require "readline" Readline.completion_append_character = "string" p Readline.completion_append_character # => "s"
Raises NotImplementedError
if the using readline library does not support.
Returns a string containing a character to be appended on completion. The default is a space (“ ”).
Raises NotImplementedError
if the using readline library does not support.