Class: XfOOrth::AbstractWordSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/fOOrth/compiler/word_specs.rb

Overview

The abstract base class for all of the different sorts of word specs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, symbol, tags = [], &block) ⇒ AbstractWordSpec

Set up the method spec.
Parameters:

  • name - The string that maps to the symbol.

  • symbol - The symbol that the name maps to.

  • tags - A an array of tags.


These may include:

  • :immediate - The word is executed, even in compile modes.

  • :macro - Identifies the spec as a macro spec to assist debugging.

  • :stub - The word is a place holder in the hierarchy.


Endemic Code Smells

  • :reek:ControlParameter – false positive



30
31
32
33
34
# File 'lib/fOOrth/compiler/word_specs.rb', line 30

def initialize(name, symbol, tags=[], &block)
  @tags = tags
  @does = block || get_stub_action(name, symbol)
  build_builds_string(name, symbol)
end

Instance Attribute Details

#buildsObject (readonly)

The compile-time text inserted into the buffer.



11
12
13
# File 'lib/fOOrth/compiler/word_specs.rb', line 11

def builds
  @builds
end

#doesObject (readonly)

The run-time action; The block that gets linked to the method’s symbol.



14
15
16
# File 'lib/fOOrth/compiler/word_specs.rb', line 14

def does
  @does
end

#tagsObject (readonly)

The attributes tagged to this specification.



17
18
19
# File 'lib/fOOrth/compiler/word_specs.rb', line 17

def tags
  @tags
end

Instance Method Details

#get_stub_action(name, symbol) ⇒ Object

Get the default action if none is specified.



37
38
39
40
41
# File 'lib/fOOrth/compiler/word_specs.rb', line 37

def get_stub_action(name, symbol)
  lambda do |*_any|
    error "F20: A #{self.foorth_name} does not understand #{name} (#{symbol.inspect})."
  end
end

#has_tag?(tag) ⇒ Boolean

Look up an tag of interest.

Returns:

  • (Boolean)


44
45
46
# File 'lib/fOOrth/compiler/word_specs.rb', line 44

def has_tag?(tag)
  @tags.include?(tag)
end