Class: KPeg::MatchString
Instance Attribute Summary collapse
-
#op ⇒ Object
readonly
Returns the value of attribute op.
-
#string ⇒ Object
(also: #total_string)
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #explain(indent = "") ⇒ Object
-
#initialize(op, string) ⇒ MatchString
constructor
A new instance of MatchString.
- #value(obj = nil) ⇒ Object
Constructor Details
#initialize(op, string) ⇒ MatchString
Returns a new instance of MatchString.
5 6 7 8 |
# File 'lib/kpeg/match.rb', line 5 def initialize(op, string) @op = op @string = string end |
Instance Attribute Details
#op ⇒ Object (readonly)
Returns the value of attribute op.
10 11 12 |
# File 'lib/kpeg/match.rb', line 10 def op @op end |
#string ⇒ Object (readonly) Also known as: total_string
Returns the value of attribute string.
10 11 12 |
# File 'lib/kpeg/match.rb', line 10 def string @string end |
Instance Method Details
#explain(indent = "") ⇒ Object
12 13 14 15 16 |
# File 'lib/kpeg/match.rb', line 12 def explain(indent="") puts "#{indent}KPeg::Match:#{object_id.to_s(16)}" puts "#{indent} op: #{@op.inspect}" puts "#{indent} string: #{@string.inspect}" end |
#value(obj = nil) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/kpeg/match.rb', line 20 def value(obj=nil) return @string unless @op.action if obj obj.instance_exec(@string, &@op.action) else @op.action.call(@string) end end |