Module: Loba::Internal::Value Private

Defined in:
lib/loba/internal/value.rb,
lib/loba/internal/value/value_helper.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Internal module for examining a value in support of Loba.value

Defined Under Namespace

Modules: ValueHelper

Class Method Summary collapse

Class Method Details

.phrases(argument:, label: nil, inspect: true, depth_offset: 0) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Retrieve a value used in code.

Parameters:

  • argument (Symbol, Object)

    the value or variable for which information is to be retrieved

    • If a symbol, it is assumed to be a reference to a variable and a label can be inferred.

    • If any other type, it is assumed to be a literal value to and a label should be supplied when instantiated.

  • label (String) (defaults to: nil)

    when provided, an explicit label to use; will override any possible inferred label

  • inspect (Boolean) (defaults to: true)

    when true, force #inspect to be called against argument when evaluating

  • depth_offset (Integer) (defaults to: 0)

    depth in call stack to start evaluation from

Returns:

  • (Hash)

    various detail about the value being analyzed

    • :tag => [String] method name (wrapped in square brackets)

    • :line => [String] code line reference

    • :value => [String] value of argument (if nil, ‘-nil-’ is returned)

    • :label => [String] label, ending with “:” (if not possible to infer, “[unknown value]” is returned)



29
30
31
32
33
34
35
36
37
# File 'lib/loba/internal/value.rb', line 29

def phrases(argument:, label: nil, inspect: true, depth_offset: 0)
  depth = depth_offset.nil? ? 0 : depth_offset.to_i
  {
    tag: ValueHelper.tag(depth: depth + 1),
    line: ValueHelper.line(depth: depth + 1),
    value: ValueHelper.value(argument: argument, inspect: inspect, depth: depth + 1),
    label: ValueHelper.label(argument: argument, explicit_label: label)
  }
end