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
.
Returns true if the method mid
have an option opt
.
p FileUtils.have_option?(:cp, :noop) #=> true p FileUtils.have_option?(:rm, :force) #=> true p FileUtils.have_option?(:rm, :preserve) #=> false
Returns an Array
of option names of the method mid
.
p FileUtils.options_of(:rm) #=> ["noop", "verbose", "force"]
Returns the convertible integer type of the given type
. You may optionally specify additional headers
to search in for the type
. convertible means actually the same type, or typedef’d from the same type.
If the type
is an integer type and the convertible type is found, the following macros are passed as preprocessor constants to the compiler using the type
name, in uppercase.
TYPEOF_
, followed by the type
name, followed by =X
where “X” is the found convertible type name.
TYP2NUM
and NUM2TYP
, where TYP
is the type
name in uppercase with replacing an _t
suffix with “T”, followed by =X
where “X” is the macro name to convert type
to an Integer
object, and vice versa.
For example, if foobar_t
is defined as unsigned long, then convertible_int("foobar_t")
would return “unsigned long”, and define these macros:
#define TYPEOF_FOOBAR_T unsigned long #define FOOBART2NUM ULONG2NUM #define NUM2FOOBART NUM2ULONG
Reads text, substituting entities
Returns true
if num
is greater than 0.
Returns true
if float
is greater than 0.
Returns the birth time for file.
File.new("testfile").birthtime #=> Wed Apr 09 08:53:14 CDT 2003
If the platform doesn’t have birthtime, raises NotImplementedError
.
Checks the compatibility of two objects.
If the objects are both strings they are compatible when they are concatenatable. The encoding of the concatenated string will be returned if they are compatible, nil if they are not.
Encoding.compatible?("\xa1".force_encoding("iso-8859-1"), "b") #=> #<Encoding:ISO-8859-1> Encoding.compatible?( "\xa1".force_encoding("iso-8859-1"), "\xa1\xa1".force_encoding("euc-jp")) #=> nil
If the objects are non-strings their encodings are compatible when they have an encoding and:
Either encoding is US-ASCII compatible
One of the encodings is a 7-bit encoding
Returns true
if rat
is greater than 0.
Returns the birth time for the file. If the platform doesn’t have birthtime, raises NotImplementedError
.
See File.birthtime
.
Returns the list of waiting threads.
When stepping through the traces of a function, thread gets suspended, to be resumed later.
Returns true
if this is an hermitian matrix. Raises an error if matrix is not square.
Sets the process title that appears on the ps(1) command. Not necessarily effective on all platforms. No exception will be raised regardless of the result, nor will NotImplementedError
be raised even if the platform does not support the feature.
Calling this method does not affect the value of $0.
Process.setproctitle('myapp: worker #%d' % worker_id)
This method first appeared in Ruby 2.1 to serve as a global variable free means to change the process title.
Reads at most maxlen bytes from the gziped stream but it blocks only if gzipreader has no data immediately available. If the optional outbuf argument is present, it must reference a String
, which will receive the data. It raises EOFError
on end of file.
for IO.copy_stream
. Note: we may return a larger string than size
here; but IO.copy_stream
does not care.