Class: MatchData
Overview
MatchData is the class of the object returned by String#match, Regexp#match, and Regexp#last_match. It encapsulates all the results of a pattern match.
Instance Method Summary collapse
- #[](*args) ⇒ Object
-
#begin(n) ⇒ Object
FIX: Incomplete.
-
#captures ⇒ Object
call-seq: mtch.captures -> array.
-
#end(n) ⇒ Object
FIX: Incomplete.
-
#initialize ⇒ MatchData
constructor
:nodoc:.
-
#inspect ⇒ Object
:nodoc:.
-
#length ⇒ Object
call-seq: mtch.length -> integer mtch.size -> integer.
-
#offset(n) ⇒ Object
FIX: Incomplete.
-
#post_match ⇒ Object
call-seq: mtch.post_match -> string.
-
#pre_match ⇒ Object
call-seq: mtch.pre_match -> string.
-
#select ⇒ Object
FIX: Incomplete.
-
#size ⇒ Object
call-seq: mtch.length -> integer mtch.size -> integer.
-
#string ⇒ Object
call-seq: mtch.string -> string.
-
#to_a ⇒ Object
call-seq: mtch.to_a -> array.
-
#to_s ⇒ Object
call-seq: mtch.to_s -> string.
-
#values_at ⇒ Object
FIX: Incomplete.
Constructor Details
#initialize ⇒ MatchData
:nodoc:
3890 3891 3892 |
# File 'lib/source/ruby.rb', line 3890 def initialize # :nodoc: `this.__captures__=[]` end |
Instance Method Details
#[](*args) ⇒ Object
call-seq:
mtch[i] -> object
mtch[start, length] -> array
mtch[range] -> array
Match Reference -- MatchData acts as an array, and may be accessed using the normal array indexing techniques. mtch returns the entire matched string, while mtch, mtch, and so on return the values of the matched backreferences (portions of the pattern between parentheses).
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m[0] #=> "HX1138"
m[1, 2] #=> ["H", "X"]
m[1..3] #=> ["H", "X", "113"]
m[-3, 2] #=> ["X", "113"]
3912 3913 3914 |
# File 'lib/source/ruby.rb', line 3912 def [](*args) `c$Array.prototype.m$_brac.apply(this.__captures__,args)` end |
#begin(n) ⇒ Object
FIX: Incomplete
3917 3918 |
# File 'lib/source/ruby.rb', line 3917 def begin(n) end |
#captures ⇒ Object
call-seq:
mtch.captures -> array
Returns the array of captures.
m = /(.)(.)(\d+)(\d)/.match("THX1138.").captures
m[0] #=> "H"
m[1] #=> "X"
m[2] #=> "113"
m[3] #=> "8"
3932 3933 3934 |
# File 'lib/source/ruby.rb', line 3932 def captures `this.__captures__.slice(1)` end |
#inspect ⇒ Object
:nodoc:
3954 3955 3956 |
# File 'lib/source/ruby.rb', line 3954 def inspect # :nodoc: `c$Object.prototype.m$to_s.apply(this)` end |
#length ⇒ Object
call-seq:
mtch.length -> integer
mtch.size -> integer
Returns the number of elements in the match array.
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.length #=> 5
3950 3951 3952 |
# File 'lib/source/ruby.rb', line 3950 def length `this.__captures__.length` end |
#offset(n) ⇒ Object
FIX: Incomplete
3959 3960 |
# File 'lib/source/ruby.rb', line 3959 def offset(n) end |
#post_match ⇒ Object
call-seq:
mtch.post_match -> string
Returns the portion of the original string after the current match.
m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
m.post_match #=> ": The Movie"
3971 3972 3973 |
# File 'lib/source/ruby.rb', line 3971 def post_match `this.__post__` end |
#pre_match ⇒ Object
call-seq:
mtch.pre_match -> string
Returns the portion of the original string before the current match.
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.pre_match #=> "T"
3984 3985 3986 |
# File 'lib/source/ruby.rb', line 3984 def pre_match `this.__pre__` end |
#size ⇒ Object
call-seq:
mtch.length -> integer
mtch.size -> integer
Returns the number of elements in the match array.
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.size #=> 5
4002 4003 4004 |
# File 'lib/source/ruby.rb', line 4002 def size `this.__captures__.length` end |
#string ⇒ Object
call-seq:
mtch.string -> string
Returns a copy of the string that was matched against a pattern to produce mtch.
m1 = /(.)(.)(\d+)(\d)/.match("THX1138.")
m2 = "THX1138.".match(/(.)(.)(\d+)(\d)/)
m1.string #=> "THX1138."
m2.string #=> "THX1138."
4018 4019 4020 |
# File 'lib/source/ruby.rb', line 4018 def string `$q(this.__string__)` end |
#to_a ⇒ Object
call-seq:
mtch.to_a -> array
Returns the MatchData's internal array.
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.to_a #=> ["HX1138", "H", "X", "113", "8"]
4031 4032 4033 |
# File 'lib/source/ruby.rb', line 4031 def to_a `this.__captures__` end |
#to_s ⇒ Object
call-seq:
mtch.to_s -> string
Returns the entire matched string.
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.to_s #=> "HX1138"
4044 4045 4046 |
# File 'lib/source/ruby.rb', line 4044 def to_s `this.__captures__[0]` end |
#values_at ⇒ Object
FIX: Incomplete
4049 4050 |
# File 'lib/source/ruby.rb', line 4049 def values_at end |