Returns the array of WIN32OLE_METHOD
object . The element of the array is property (settable) of WIN32OLE
object.
excel = WIN32OLE.new('Excel.Application') properties = excel.ole_func_methods
Computes and returns or yields all combinations of elements from all the Arrays, including both self
and other_arrays
.
The number of combinations is the product of the sizes of all the arrays, including both self
and other_arrays
.
The order of the returned combinations is indeterminate.
When no block is given, returns the combinations as an Array of Arrays:
a = [0, 1, 2] a1 = [3, 4] a2 = [5, 6] p = a.product(a1) p.size # => 6 # a.size * a1.size p # => [[0, 3], [0, 4], [1, 3], [1, 4], [2, 3], [2, 4]] p = a.product(a1, a2) p.size # => 12 # a.size * a1.size * a2.size p # => [[0, 3, 5], [0, 3, 6], [0, 4, 5], [0, 4, 6], [1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, 5], [2, 4, 6]]
If any argument is an empty Array, returns an empty Array.
If no argument is given, returns an Array of 1-element Arrays, each containing an element of self
:
a.product # => [[0], [1], [2]]
When a block is given, yields each combination as an Array; returns self
:
a.product(a1) {|combination| p combination }
Output:
[0, 3] [0, 4] [1, 3] [1, 4] [2, 3] [2, 4]
If any argument is an empty Array, does not call the block:
a.product(a1, a2, []) {|combination| fail 'Cannot happen' }
If no argument is given, yields each element of self
as a 1-element Array:
a.product {|combination| p combination }
Output:
[0] [1] [2]
Turns the database’s synchronization mode on or off. If the synchronization mode is turned on, the database’s in-memory state will be synchronized to disk after every database modification operation. If the synchronization mode is turned off, GDBM
does not wait for writes to be flushed to the disk before continuing.
This option is only available for gdbm >= 1.8 where syncmode is turned off by default. See also: fastmode=
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.
Invoked as a callback whenever a singleton method is added to the receiver.
module Chatty def Chatty.singleton_method_added(id) puts "Adding #{id.id2name}" end def self.one() end def two() end def Chatty.three() end end
produces:
Adding singleton_method_added Adding one Adding three
Returns a data represents the current console mode.
You must require ‘io/console’ to use this method.
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.
Returns a new array with the concatenated results of running block once for every element in enum.
If no block is given, an enumerator is returned instead.
[1, 2, 3, 4].flat_map { |e| [e, -e] } #=> [1, -1, 2, -2, 3, -3, 4, -4] [[1, 2], [3, 4]].flat_map { |e| e + [100] } #=> [1, 2, 100, 3, 4, 100]
Enters exclusive section and executes the block. Leaves the exclusive section automatically when the block exits. See example under MonitorMixin
.
Returns the source file origin 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 a new lazy enumerator with the concatenated results of running block
once for every element in the lazy enumerator.
["foo", "bar"].lazy.flat_map {|i| i.each_char.lazy}.force #=> ["f", "o", "o", "b", "a", "r"]
A value x
returned by block
is decomposed if either of the following conditions is true:
x
responds to both each and force, which means that x
is a lazy enumerator.
x
is an array or responds to to_ary.
Otherwise, x
is contained as-is in the return value.
[{a:1}, {b:2}].lazy.flat_map {|i| i}.force #=> [{:a=>1}, {:b=>2}]
Returns the destination encoding as an encoding object.
Returns the destination encoding as an encoding object.
Returns the destination encoding as an Encoding
object.
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.
When called during a completion (e.g. from within your completion_proc
), it will return a string containing the character used to quote the argument being completed, or nil if the argument is unquoted.
When called at other times, it will always return nil.
Note that Readline.completer_quote_characters
must be set, or this method will always return nil.
Returns an array of the names of singleton methods for obj. If the optional all parameter is true, the list will include methods in modules included in obj. Only public and protected singleton methods are returned.
module Other def three() end end class Single def Single.four() end end a = Single.new def a.one() end class << a include Other def two() end end Single.singleton_methods #=> [:four] a.singleton_methods(false) #=> [:two, :one] a.singleton_methods #=> [:two, :one, :three]
Similar to method, searches singleton method only.
class Demo def initialize(n) @iv = n end def hello() "Hello, @iv = #{@iv}" end end k = Demo.new(99) def k.hi "Hi, @iv = #{@iv}" end m = k.singleton_method(:hi) m.call #=> "Hi, @iv = 99" m = k.singleton_method(:hello) #=> NameError