Creates a new Proc
object, bound to the current context. Proc::new
may be called without a block only within a method with an attached block, in which case that block is converted to the Proc
object.
def proc_from Proc.new end proc = proc_from { "hello" } proc.call #=> "hello"
Creates a new PRNG using seed
to set the initial state. If seed
is omitted, the generator is initialized with Random.new_seed
.
See Random.srand
for more information on the use of seed values.
Document-class: UncaughtThrowError
Raised when throw
is called with a tag which does not have corresponding catch
block.
throw "foo", "bar"
raises the exception:
UncaughtThrowError: uncaught throw "foo"
Returns a new TracePoint
object, not enabled by default.
Next, in order to activate the trace, you must use TracePoint.enable
trace = TracePoint.new(:call) do |tp| p [tp.lineno, tp.defined_class, tp.method_id, tp.event] end #=> #<TracePoint:disabled> trace.enable #=> false puts "Hello, TracePoint!" # ... # [48, IRB::Notifier::AbstractNotifier, :printf, :call] # ...
When you want to deactivate the trace, you must use TracePoint.disable
trace.disable
See Events at TracePoint
for possible events and more information.
A block must be given, otherwise a ThreadError
is raised.
If the trace method isn’t included in the given events filter, a RuntimeError
is raised.
TracePoint.trace(:line) do |tp| p tp.raised_exception end #=> RuntimeError: 'raised_exception' not supported by this event
If the trace method is called outside block, a RuntimeError
is raised.
TracePoint.trace(:line) do |tp| $tp = tp end $tp.line #=> access from outside (RuntimeError)
Access from other threads is also forbidden.
Use extend MonitorMixin
or include MonitorMixin
instead of this constructor. Have look at the examples above to understand how to use this module.
Duplicates self and resets its day of calendar reform.
d = Date.new(1582,10,15) d.new_start(Date::JULIAN) #=> #<Date: 1582-10-05 ...>
Returns OLE event object. The first argument specifies WIN32OLE
object. The second argument specifies OLE event name.
ie = WIN32OLE.new('InternetExplorer.Application') ev = WIN32OLE_EVENT.new(ie, 'DWebBrowserEvents')
Returns a new WIN32OLE_METHOD
object which represents the information about OLE method. The first argument ole_type specifies WIN32OLE_TYPE
object. The second argument method specifies OLE method name defined OLE class which represents WIN32OLE_TYPE
object.
tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Workbook') method = WIN32OLE_METHOD.new(tobj, 'SaveAs')
Returns WIN32OLE_PARAM
object which represents OLE parameter information. 1st argument should be WIN32OLE_METHOD
object. 2nd argument ‘n’ is n-th parameter of the method specified by 1st argument.
tobj = WIN32OLE_TYPE.new('Microsoft Scripting Runtime', 'IFileSystem') method = WIN32OLE_METHOD.new(tobj, 'CreateTextFile') param = WIN32OLE_PARAM.new(method, 2) # => #<WIN32OLE_PARAM:Overwrite=true>
Returns WIN32OLE_RECORD
object. The first argument is struct name (String or Symbol
). The second parameter obj should be WIN32OLE
object or WIN32OLE_TYPELIB
object. If COM server in VB.NET ComServer project is the following:
Imports System.Runtime.InteropServices Public Class ComClass Public Structure Book <MarshalAs(UnmanagedType.BStr)> _ Public title As String Public cost As Integer End Structure End Class
then, you can create WIN32OLE_RECORD
object is as following:
require 'win32ole' obj = WIN32OLE.new('ComServer.ComClass') book1 = WIN32OLE_RECORD.new('Book', obj) # => WIN32OLE_RECORD object tlib = obj.ole_typelib book2 = WIN32OLE_RECORD.new('Book', tlib) # => WIN32OLE_RECORD object
Returns a new WIN32OLE_TYPE
object. The first argument typelib specifies OLE type library name. The second argument specifies OLE class name.
WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Application') # => WIN32OLE_TYPE object of Application class of Excel.
Returns a new WIN32OLE_TYPELIB
object.
The first argument typelib specifies OLE type library name or GUID or OLE library file. The second argument is major version or version of the type library. The third argument is minor version. The second argument and third argument are optional. If the first argument is type library name, then the second and third argument are ignored.
tlib1 = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') tlib2 = WIN32OLE_TYPELIB.new('{00020813-0000-0000-C000-000000000046}') tlib3 = WIN32OLE_TYPELIB.new('{00020813-0000-0000-C000-000000000046}', 1.3) tlib4 = WIN32OLE_TYPELIB.new('{00020813-0000-0000-C000-000000000046}', 1, 3) tlib5 = WIN32OLE_TYPELIB.new("C:\\WINNT\\SYSTEM32\\SHELL32.DLL") puts tlib1.name # -> 'Microsoft Excel 9.0 Object Library' puts tlib2.name # -> 'Microsoft Excel 9.0 Object Library' puts tlib3.name # -> 'Microsoft Excel 9.0 Object Library' puts tlib4.name # -> 'Microsoft Excel 9.0 Object Library' puts tlib5.name # -> 'Microsoft Shell Controls And Automation'
Returns Ruby object wrapping OLE variant. The first argument specifies Ruby object to convert OLE variant variable. The second argument specifies VARIANT type. In some situation, you need the WIN32OLE_VARIANT
object to pass OLE method
shell = WIN32OLE.new("Shell.Application") folder = shell.NameSpace("C:\\Windows") item = folder.ParseName("tmp.txt") # You can't use Ruby String object to call FolderItem.InvokeVerb. # Instead, you have to use WIN32OLE_VARIANT object to call the method. shortcut = WIN32OLE_VARIANT.new("Create Shortcut(\&S)") item.invokeVerb(shortcut)
Duplicates self and resets its offset.
d = DateTime.new(2001,2,3,4,5,6,'-02:00') #=> #<DateTime: 2001-02-03T04:05:06-02:00 ...> d.new_offset('+09:00') #=> #<DateTime: 2001-02-03T15:05:06+09:00 ...>
Returns a new binding each time near TOPLEVEL_BINDING for runs that do not specify a binding.
Creates a new ipaddr containing the given network byte ordered string form of an IP address.
Returns an arbitrary seed value. This is used by Random.new
when no seed value is specified as an argument.
Random.new_seed #=> 115032730400174366788466674494640623225
Creates a new MonitorMixin::ConditionVariable
associated with the receiver.
Creates a new Lazy
enumerator. When the enumerator is actually enumerated (e.g. by calling force), obj
will be enumerated and each value passed to the given block. The block can yield values back using yielder
. For example, to create a method filter_map
in both lazy and non-lazy fashions:
module Enumerable def filter_map(&block) map(&block).compact end end class Enumerator::Lazy def filter_map Lazy.new(self) do |yielder, *values| result = yield *values yielder << result if result end end end (1..Float::INFINITY).lazy.filter_map{|i| i*i if i.even?}.first(5) # => [4, 16, 36, 64, 100]