A detailed description of this gem. See also summary
Creates a class to wrap the C union described by signature
.
MyUnion = union ['int i', 'char c']
Generate a Table Caption element as a string.
align
can be a string, giving the alignment of the caption (one of top, bottom, left, or right). It can be a hash of all the attributes of the element. Or it can be omitted.
The body of the element is provided by the passed-in no-argument block.
caption("left") { "Capital Cities" } # => <CAPTION ALIGN=\"left\">Capital Cities</CAPTION>
Sets OptionParser
object, when opt
is false
or nil
, methods OptionParser::Arguable#options
and OptionParser::Arguable#options=
are undefined. Thus, there is no ways to access the OptionParser
object via the receiver object.
Actual OptionParser
object, automatically created if nonexistent.
If called with a block, yields the OptionParser
object and returns the result of the block. If an OptionParser::ParseError
exception occurs in the block, it is rescued, a error message printed to STDERR and nil
returned.
<!NOTATION …>
<!NOTATION …>
Starts tracing object allocations.
Stop tracing object allocations.
Note that if ::trace_object_allocations_start
is called n-times, then tracing will stop after calling ::trace_object_allocations_stop
n-times.
The iterator version of the strongly_connected_components
method. obj.each_strongly_connected_component
is similar to obj.strongly_connected_components.each
, but modification of obj during the iteration may lead to unexpected results.
each_strongly_connected_component
returns nil
.
class G include TSort def initialize(g) @g = g end def tsort_each_child(n, &b) @g[n].each(&b) end def tsort_each_node(&b) @g.each_key(&b) end end graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}) graph.each_strongly_connected_component {|scc| p scc } #=> [4] # [2] # [3] # [1] graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}) graph.each_strongly_connected_component {|scc| p scc } #=> [4] # [2, 3] # [1]
The iterator version of the TSort.strongly_connected_components
method.
The graph is represented by each_node and each_child. each_node should have call
method which yields for each node in the graph. each_child should have call
method which takes a node argument and yields for each child node.
g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]} each_node = lambda {|&b| g.each_key(&b) } each_child = lambda {|n, &b| g[n].each(&b) } TSort.each_strongly_connected_component(each_node, each_child) {|scc| p scc } #=> [4] # [2] # [3] # [1] g = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]} each_node = lambda {|&b| g.each_key(&b) } each_child = lambda {|n, &b| g[n].each(&b) } TSort.each_strongly_connected_component(each_node, each_child) {|scc| p scc } #=> [4] # [2, 3] # [1]
Appends the elements of other_ary
to self
.
[ "a", "b" ].concat( ["c", "d"] ) #=> [ "a", "b", "c", "d" ] a = [ 1, 2, 3 ] a.concat( [ 4, 5 ] ) a #=> [ 1, 2, 3, 4, 5 ]
See also Array#+
.
Returns num
truncated to an Integer
.
Numeric
implements this by converting its value to a Float
and invoking Float#truncate
.
Append—Concatenates the given object to str. If the object is a Integer
, it is considered as a codepoint, and is converted to a character before concatenation.
a = "hello " a << "world" #=> "hello world" a.concat(33) #=> "hello world!"
Returns the change time for the named file (the time at which directory information about the file was changed, not the file itself).
file_name can be an IO
object.
Note that on Windows (NTFS), returns creation time (birth time).
File.ctime("testfile") #=> Wed Apr 09 08:53:13 CDT 2003
Truncates the file file_name to be at most integer bytes long. Not available on all platforms.
f = File.new("out", "w") f.write("1234567890") #=> 10 f.close #=> nil File.truncate("out", 5) #=> 0 File.size("out") #=> 5
Returns the change time for file (that is, the time directory information about the file was changed, not the file itself).
Note that on Windows (NTFS), returns creation time (birth time).
File.new("testfile").ctime #=> Wed Apr 09 08:53:14 CDT 2003
Truncates file to at most integer bytes. The file must be opened for writing. Not available on all platforms.
f = File.new("out", "w") f.syswrite("1234567890") #=> 10 f.truncate(5) #=> 0 f.close() #=> nil File.size("out") #=> 5
Truncate to the nearest integer (by default), returning the result as a BigDecimal
.
BigDecimal('3.14159').truncate #=> 3 BigDecimal('8.7').truncate #=> 8 BigDecimal('-9.9').truncate #=> -9
If n is specified and positive, the fractional part of the result has no more than that many digits.
If n is specified and negative, at least that many digits to the left of the decimal point will be 0 in the result.
BigDecimal('3.14159').truncate(3) #=> 3.141 BigDecimal('13345.234').truncate(-2) #=> 13300.0
As int
is already an Integer
, all these methods simply return the receiver.