class Object

Extensions to the Object class required by the fOOrth language system.

Public Instance Methods

cache_exclusive_method(symbol, &block) click to toggle source

Load the new exclusive method into the object.

# File lib/fOOrth/core/object.rb, line 43
def cache_exclusive_method(symbol, &block)
  define_singleton_method(symbol, &block)
rescue TypeError
  error "F13: Exclusive methods not allowed for type: #{self.class.foorth_name}"
end
create_exclusive_method(name, spec_class, options, &block) click to toggle source

Create an exclusive method on this fOOrth object.
Parameters:

  • name - The name of the method to create.

  • spec_class - The specification class to use.

  • options - An array of options.

  • block - A block to associate with the name.


Returns

  • The spec created for the shared method.

# File lib/fOOrth/core/object.rb, line 35
def create_exclusive_method(name, spec_class, options, &block)
  sym = XfOOrth::SymbolMap.add_entry(name)
  spec = spec_class.new(name, sym, options, &block)
  cache_exclusive_method(sym, &spec.does)
  foorth_exclusive[sym] = spec
end
error(msg) click to toggle source

Fail with XfOOrthError argument error.

# File lib/fOOrth/monkey_patch/object.rb, line 37
def error(msg)
  fail XfOOrth::XfOOrthError, msg, caller
end
f20_error(recvr, name, symbol) click to toggle source

A helper macro for method not understood errors.

# File lib/fOOrth/monkey_patch/object.rb, line 42
def f20_error(recvr, name, symbol)
  fail XfOOrth::XfOOrthError,
       "F20: A #{recvr.foorth_name} does not understand #{name} (#{symbol.inspect}).",
       caller
end
foorth_coerce(_arg) click to toggle source

Coerce the argument to match my type. Stub

# File lib/fOOrth/monkey_patch/object.rb, line 51
def foorth_coerce(_arg)
  error "F40: Cannot coerce to a #{self.foorth_name}"
end
foorth_embed() click to toggle source

Raise a fOOrth language internal exception as this operation is not allowed.

# File lib/fOOrth/monkey_patch/object.rb, line 7
def foorth_embed
  error "F40: Can't embed class #{self.class.foorth_class_name}"
end
foorth_exclusive() click to toggle source

Access/create the object's exclusive fOOrth dictionary.
Decree!

  • This method and the next are to be the only references to the @_private_foorth_exclusive variable.

# File lib/fOOrth/core/object.rb, line 15
def foorth_exclusive
  @_private_foorth_exclusive ||= Hash.new
end
foorth_has_exclusive?() click to toggle source

Does this object have exclusive methods defined on it?
Decree!

  • This method and the previous are to be the only references to the @_private_foorth_exclusive variable.

# File lib/fOOrth/core/object.rb, line 23
def foorth_has_exclusive?
  instance_variable_defined?(:@_private_foorth_exclusive)
end
foorth_method_info(name) click to toggle source

Investigate a method of this object.
Endemic Code Smells

  • :reek:FeatureEnvy

# File lib/fOOrth/library/introspection/object.rb, line 29
def foorth_method_info(name)
  symbol, results = XfOOrth::SymbolMap.map_info(name)
  found = false

  if symbol
    spec, info = map_foorth_exclusive_info(symbol)

    if spec && !spec.has_tag?(:stub)
      (results << ["", ""]).concat(info).concat(spec.get_info)
      found = true
    end

    results << ["Scope", "not found."] unless found
  end

  results
end
foorth_name() click to toggle source

Get the foorth name of this object.

# File lib/fOOrth/core/object.rb, line 7
def foorth_name
  "#{self.class.foorth_name} instance".freeze
end
foorth_string_freeze() click to toggle source

Freeze only pure strings

# File lib/fOOrth/monkey_patch/object.rb, line 32
def foorth_string_freeze
  self
end
format_description(max_width) click to toggle source

Create a bullet point description from this object.

# File lib/fOOrth/library/formatting/object.rb, line 7
def format_description(max_width)
  self.to_s.format_description(max_width)
end
full_clone_exclude() click to toggle source

The full clone data member clone exclusion control

# File lib/fOOrth/library/clone_library.rb, line 35
def full_clone_exclude
  vm = Thread.current[:vm]
  self.foorth_exclude(vm)

  vm.pop.map do |entry|
    if (sym = XfOOrth::SymbolMap.map(entry))
      ("@" + sym.to_s).to_sym
    else
      entry
    end
  end
end
get_info() click to toggle source

Get introspection info.

# File lib/fOOrth/library/introspection/object.rb, line 18
def get_info
  results = [["Type", foorth_name]]
  get_instance_variable_info(results)
  get_exclusive_method_info(results, "Exclusive")

  results
end
lineage() click to toggle source

Get the lineage of this object.

# File lib/fOOrth/library/introspection/object.rb, line 48
def lineage
  foorth_name + " < " + self.class.lineage
end
map_foorth_exclusive(symbol) click to toggle source

Map the symbol to a specification or nil if there is no mapping.

# File lib/fOOrth/core/object.rb, line 50
def map_foorth_exclusive(symbol)
  (foorth_has_exclusive? && foorth_exclusive[symbol]) ||
  self.class.map_foorth_shared(symbol)
end
map_foorth_exclusive_info(symbol, shallow=nil) click to toggle source

Map the symbol to a specification or nil if there is no mapping.

# File lib/fOOrth/library/introspection/object.rb, line 7
def map_foorth_exclusive_info(symbol, shallow=nil)
  if (foorth_has_exclusive? && (spec = foorth_exclusive[symbol]))
    [spec, [["Object", foorth_name], ["Scope", "Exclusive"]]]
  elsif !shallow
    self.class.map_foorth_shared_info(symbol)
  else
    [nil, nil]
  end
end
method_missing(symbol, *args, &block) click to toggle source

The method_missing hook is used to provide meaningful error messages when problems are encountered.
Parameters:

  • symbol - The symbol of the missing method.

  • args - Any arguments that were passed to that method.

  • block - Any block that might have passed to the method.


Note:

  • Since stubs for Object class do not create methods, an attempt is made to execute the stub if the symbol maps and is in the Object class. This ensures that the case specific stub code is used rather than the generic code in this method.

Calls superclass method
# File lib/fOOrth/core/object.rb, line 66
def method_missing(symbol, *args, &block)
  if (name = XfOOrth::SymbolMap.unmap(symbol))
    if (stub_spec = Object.foorth_shared[symbol])
      self.instance_exec(*args, &stub_spec.does)
    else
      f20_error(self, name, symbol)
    end
  else
    super
  end
end
prepare_bullet_data() click to toggle source

Get data ready for being in a bullet point.

# File lib/fOOrth/library/formatting/object.rb, line 12
def prepare_bullet_data
  ["*", self]
end
to_foorth_b() click to toggle source

Convert this object to a fOOrth boolean.

# File lib/fOOrth/monkey_patch/object.rb, line 12
def to_foorth_b
  true
end
to_foorth_c() click to toggle source

Convert this object to a single character string.

# File lib/fOOrth/monkey_patch/object.rb, line 17
def to_foorth_c
  "\x00"
end
to_foorth_n() click to toggle source

Convert this object to a numeric. Returns nil for fail.

# File lib/fOOrth/monkey_patch/object.rb, line 22
def to_foorth_n
  nil
end
to_foorth_r() click to toggle source

Convert this object to a rational. Returns nil for fail.

# File lib/fOOrth/monkey_patch/object.rb, line 27
def to_foorth_r
  nil
end

Private Instance Methods

get_exclusive_method_info(results, designation) click to toggle source

Get exclusive method info

# File lib/fOOrth/library/introspection/object.rb, line 75
def get_exclusive_method_info(results, designation)
  if foorth_has_exclusive?
    results.concat([["", ""], ["Methods", designation]])

    foorth_exclusive.extract_method_names(:all).sort.each do |name|
      symbol, info = XfOOrth::SymbolMap.map_info(name)
      (results << ["", ""]).concat(info)

      spec, info = map_foorth_exclusive_info(symbol, :shallow)
      results.concat(info).concat(spec.get_info)
    end
  end
end
get_instance_variable_info(results) click to toggle source

Get information about instance variables

# File lib/fOOrth/library/introspection/object.rb, line 55
def get_instance_variable_info(results)
  names = instance_variables.map do |sym|
    if (name = XfOOrth::SymbolMap.unmap(sym.to_s[1..-1].to_sym))
      [name, sym]
    end
  end
  .compact
  .sort {|first, second| first[0] <=> second[0] }

  unless names.empty?
    results.concat([["", ""], ["Data", "Instance"], ["", ""]])

    names.each do |name, sym|
      results << [name, instance_variable_get(sym)]
    end
  end
end