Class: KPeg::MatchString

Inherits:
Match
  • Object
show all
Defined in:
lib/kpeg/match.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#opObject (readonly)

Returns the value of attribute op.



10
11
12
# File 'lib/kpeg/match.rb', line 10

def op
  @op
end

#stringObject (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