Returns any backtrace associated with the exception. This method is similar to Exception#backtrace
, but the backtrace is an array of Thread::Backtrace::Location
.
This method is not affected by Exception#set_backtrace()
.
Creates module functions for the named methods. These functions may be called with the module as a receiver, and also become available as instance methods to classes that mix in the module. Module
functions are copies of the original, and so may be changed independently. The instance-method versions are made private. If used with no arguments, subsequently defined methods become module functions. String
arguments are converted to symbols. If a single argument is passed, it is returned. If no argument is passed, nil is returned. If multiple arguments are passed, the arguments are returned as an array.
module Mod def one "This is one" end module_function :one end class Cls include Mod def call_one one end end Mod.one #=> "This is one" c = Cls.new c.call_one #=> "This is one" module Mod def one "This is the new one" end end Mod.one #=> "This is one" c.call_one #=> "This is the new one"
Returns the fractional part of the day.
DateTime.new(2001,2,3,12).day_fraction #=> (1/2)
Returns the fractional part of the second.
DateTime.new(2001,2,3,4,5,6.5).sec_fraction #=> (1/2)
Clone internal hash.
Set options. Takes the same argument as GetoptLong.new
.
Raises a RuntimeError
if option processing has already started.
‘get_option’ is an alias of ‘get’.
‘each_option’ is an alias of ‘each’.
Returns the Ruby source filename and line number of the binding object.
Raises PStore::Error
if the calling code is not in a PStore#transaction
.
List of options that will be supplied to RDoc
Returns the Ruby source filename and line number containing this proc or nil
if this proc was not defined in Ruby (i.e. native).
Returns the Ruby source filename and line number containing this method or nil if this method was not defined in Ruby (i.e. native).
Returns the Ruby source filename and line number containing this method or nil if this method was not defined in Ruby (i.e. native).
Returns the execution stack for the target thread—an array containing backtrace location objects.
See Thread::Backtrace::Location
for more information.
This method behaves similarly to Kernel#caller_locations
except it applies to a specific thread.
Value from exception raised on the :raise
event
Compiled instruction sequence represented by a RubyVM::InstructionSequence
instance on the :script_compiled
event.
Note that this method is MRI specific.
Returns the current execution stack—an array containing backtrace location objects.
See Thread::Backtrace::Location
for more information.
The optional start parameter determines the number of initial stack entries to omit from the top of the stack.
A second optional length
parameter can be used to limit how many entries are returned from the stack.
Returns nil
if start is greater than the size of current execution stack.
Optionally you can pass a range, which will return an array containing the entries within the specified range.
Initializes the MonitorMixin
after being included in a class or when an object has been extended with the MonitorMixin
Returns the source file origin from the given object
.
See ::trace_object_allocations
for more information and examples.
Returns the original line from source for from the given object
.
See ::trace_object_allocations
for more information and examples.
Specifies a Proc
object proc
to determine completion behavior. It should take input string and return an array of completion candidates.
The default completion is used if proc
is nil.
The String
that is passed to the Proc
depends on the Readline.completer_word_break_characters
property. By default the word under the cursor is passed to the Proc
. For example, if the input is “foo bar” then only “bar” would be passed to the completion Proc
.
Upon successful completion the Readline.completion_append_character
will be appended to the input so the user can start working on their next argument.
require 'readline' LIST = [ 'search', 'download', 'open', 'help', 'history', 'quit', 'url', 'next', 'clear', 'prev', 'past' ].sort comp = proc { |s| LIST.grep(/^#{Regexp.escape(s)}/) } Readline.completion_append_character = " " Readline.completion_proc = comp while line = Readline.readline('> ', true) p line end
require 'readline' Readline.completion_append_character = " " Readline.completion_proc = Proc.new do |str| Dir[str+'*'].grep(/^#{Regexp.escape(str)}/) end while line = Readline.readline('> ', true) p line end
When working with auto-complete there are some strategies that work well. To get some ideas you can take a look at the completion.rb file for irb.
The common strategy is to take a list of possible completions and filter it down to those completions that start with the user input. In the above examples Enumerator.grep
is used. The input is escaped to prevent Regexp
special characters from interfering with the matching.
It may also be helpful to use the Abbrev
library to generate completions.
Raises ArgumentError
if proc
does not respond to the call method.
Returns the completion Proc
object.
Returns the number of malloc() allocations.
Only available if ruby was built with CALC_EXACT_MALLOC_SIZE
.