Class: RPrec::Op

Inherits:
Object
  • Object
show all
Defined in:
lib/rprec/op.rb

Overview

Op is an operator.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, key, parts, build) ⇒ Op

Returns a new instance of Op.

Parameters:

  • type (:prefix, :postfix, :non_assoc_prefix, :non_assoc_postfix, :closed, :left_assoc, :right_assoc, :non_assoc)
  • key (String)
  • parts (Array<String, Symbol>)
  • build (Proc)


10
11
12
13
14
15
# File 'lib/rprec/op.rb', line 10

def initialize(type, key, parts, build)
  @type = type
  @key = key
  @parts = parts
  @build = build
end

Instance Attribute Details

#keyString (readonly)

Returns:

  • (String)


22
23
24
# File 'lib/rprec/op.rb', line 22

def key
  @key
end

#partsArray<String, Symbol> (readonly)

Returns:

  • (Array<String, Symbol>)


24
25
26
# File 'lib/rprec/op.rb', line 24

def parts
  @parts
end

#type:prefix, ... (readonly)

Returns:

  • (:prefix, :postfix, :non_assoc_prefix, :non_assoc_postfix, :closed, :left_assoc, :right_assoc, :non_assoc)


20
21
22
# File 'lib/rprec/op.rb', line 20

def type
  @type
end

Instance Method Details

#build(*args) ⇒ Object

Parameters:

Returns:

  • (Object)


30
31
32
# File 'lib/rprec/op.rb', line 30

def build(*args)
  @build.call(*args)
end

#inspectString

Returns:

  • (String)


37
38
39
# File 'lib/rprec/op.rb', line 37

def inspect
  "#{type} #{([key] + parts).map(&:inspect).join(', ')}"
end