Module: Rib::Anchor::Imp

Included in:
Rib
Defined in:
lib/rib/more/anchor.rb

Instance Method Summary collapse

Instance Method Details

#anchor(obj_or_binding, opts = {}) ⇒ Rib::Skip

Enter an interactive Rib shell based on a particular context.

Examples:

Rib.anchor binding
Rib.anchor 123

Parameters:

  • obj_or_binding (Object, Binding)

    The context of the shell.

  • opts (Hash) (defaults to: {})

    The config hash passed to the newly created shell. See Shell#initialize for all possible options.

Returns:

  • (Rib::Skip)

    This is the mark telling Rib do not print anything. It’s only used internally in Rib.

See Also:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rib/more/anchor.rb', line 68

def anchor obj_or_binding, opts={}
  return if Rib::Anchor.disabled?

  if Rib.shell.running?
    Rib.shells << Rib::Shell.new(
      Rib.shell.config.merge( :binding       => obj_or_binding,
                              :prompt_anchor => true         ).
                       merge(opts))
  else
      Rib.shell.config.merge!(:binding       => obj_or_binding,
                              :prompt_anchor => true         ).
                       merge!(opts)
  end

  Rib.shell.loop
  Rib::Skip

ensure
  Rib.shells.pop
end