Class: Briefly::Facade

Inherits:
Object
  • Object
show all
Defined in:
lib/briefly/facade.rb

Overview

The object returned by define. Shortcuts are compiled onto its singleton class as real methods, so respond_to?, console tab-completion and test stubbing all work unaided.

Memo store: reads are lock-free against a frozen snapshot hash; writes swap in a new frozen hash under a reentrant Monitor, because a memoized body may call another memoized shortcut.

Defined Under Namespace

Classes: Control

Constant Summary collapse

RESERVED =

Names a shortcut may not take: every facade method, plus Briefly's own private ones, plus the Kernel private methods the facade itself calls with an implicit receiver. Other Kernel privates (+puts+, format, ...) are deliberately absent: shadowing those is the user's call.

(Facade.instance_methods + Facade.private_instance_methods(false) + %i[raise]).freeze

Instance Method Summary collapse

Constructor Details

#initializeFacade

Returns a new instance of Facade.



12
13
14
15
16
17
18
19
20
# File 'lib/briefly/facade.rb', line 12

def initialize
  @__defs = {}
  @__aliases = {}
  @__memos = {}.freeze
  @__monitor = Monitor.new
  @__rescues = Rescues.new
  @__installed = [].freeze
  @__children = {}
end

Instance Method Details

#brieflyControl

The single public door to a facade's management operations, so those five names stay free for shortcuts. A fresh Control each call is stateless and thread-safe — nothing to race on — and an allocation is trivial next to how rarely management runs; identity across calls is not guaranteed.

Returns:



27
# File 'lib/briefly/facade.rb', line 27

def briefly = Control.new(self)

#inspectString Also known as: to_s

Returns a summary listing shortcut names; never dumps memo internals.

Returns:

  • (String)

    a summary listing shortcut names; never dumps memo internals



30
# File 'lib/briefly/facade.rb', line 30

def inspect = "#<#{self.class.name} shortcuts=#{__shortcuts.inspect}>"