Class: Korekto::Syntax

Inherits:
Object
  • Object
show all
Defined in:
lib/korekto/syntax.rb

Instance Method Summary collapse

Constructor Details

#initializeSyntax

Returns a new instance of Syntax.



3
# File 'lib/korekto/syntax.rb', line 3

def initialize = @a=[]

Instance Method Details

#each(&blk) ⇒ Object



4
# File 'lib/korekto/syntax.rb', line 4

def each(&blk) = @a.each{|s| blk[s]}

#push(s) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/korekto/syntax.rb', line 6

def push(s)
  # ensure it'll eval on string and returns boolean
  b = ''.instance_eval(s)
  # rubocop: disable Style/DoubleNegation
  raise Error, 'syntax rule must eval boolean' unless b==!!b
  # rubocop: enable Style/DoubleNegation
  @a.push(s)
rescue StandardError
  raise if $!.is_a? Error
  raise Error, "#{$!.class}: #{s}"
end