Returns the array of matches.
m = /(.)(.)(\d+)(\d)/.match("THX1138.") m.to_a #=> ["HX1138", "H", "X", "113", "8"]
Because to_a
is called when expanding *
variable, there’s a useful assignment shortcut for extracting matched fields. This is slightly slower than accessing the fields directly (as an intermediate array is generated).
all,f1,f2,f3 = * /(.)(.)(\d+)(\d)/.match("THX1138.") all #=> "HX1138" f1 #=> "H" f2 #=> "X" f3 #=> "113"
Returns the array of captures; equivalent to mtch.to_a[1..-1]
.
f1,f2,f3,f4 = /(.)(.)(\d+)(\d)/.match("THX1138.").captures f1 #=> "H" f2 #=> "X" f3 #=> "113" f4 #=> "8"
Returns the entire matched string.
m = /(.)(.)(\d+)(\d)/.match("THX1138.") m.to_s #=> "HX1138"
Returns a frozen copy of the string passed in to match
.
m = /(.)(.)(\d+)(\d)/.match("THX1138.") m.string #=> "THX1138."
This is a convenience method which is same as follows:
begin q = PrettyPrint.new(output, maxwidth, newline, &genspace) ... q.flush output end
This says “you can break a line here if necessary”, and a width
-column text sep
is inserted if a line is not broken at the point.
If sep
is not specified, “ ” is used.
If width
is not specified, sep.length
is used. You will have to specify this when sep
is a multibyte character, for example.
Increases left margin after newline with indent
for line breaks added in the block.
Convert int
to a BigDecimal
and return it.
require 'bigdecimal' require 'bigdecimal/util' 42.to_d # => #<BigDecimal:1008ef070,'0.42E2',9(36)>
Iterates the given block, passing in integer values from int
up to and including limit
.
If no block is given, an Enumerator
is returned instead.
For example:
5.upto(10) { |i| print i, " " } #=> 5 6 7 8 9 10
Iterates the given block, passing decreasing values from int
down to and including limit
.
If no block is given, an Enumerator
is returned instead.
5.downto(1) { |n| print n, ".. " } print " Liftoff!\n" #=> "5.. 4.. 3.. 2.. 1.. Liftoff!"
Returns the int
itself.
?a.ord #=> 97
This method is intended for compatibility to character constant in Ruby 1.9.
For example, ?a.ord returns 97 both in 1.8 and 1.9.
As int
is already an Integer
, all these methods simply return the receiver.
As int
is already an Integer
, all these methods simply return the receiver.
Returns the value as a rational.
1.to_r #=> (1/1) (1<<64).to_r #=> (18446744073709551616/1)
Looks up the first IP address for name
.
Looks up all IP address for name
.
Looks up the first IP address for name
.
Looks up all IP address for name
.
The content of the TempIO
as a String.
Replaces the contents of the set with the contents of the given enumerable object and returns self.
Converts the set to an array. The order of elements is uncertain.
Equivalent to Set#delete_if
, but returns nil if no changes were made.