Sha256: f7ba5a7c81107bf306c31c8792018bc7ccd579fddf1beb0d313641493889458d

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

# encoding: utf-8

require_relative '../../y_support'

# Inert recorder is similar to a null object in the sense, that in response to
# almost all messages it returns self. But in addition, it records received
# messages along with their arguments and blocks (if given). Recoded messages
# are available via #recorded_messages reader, aliased #ρ (small Greek rho).
# Inert recorder does not require any arguments for initalization, but if they
# are supplied, they are silently recoded into @init_args (for arguments) and
# @init_block (for block, if given) instance variables, exposed via standard
# readers.
# 
class InertRecorder
  attr_reader :init_args, :init_block, :recorded_messages
  alias ρ recorded_messages

  # No arguments are required for initialization, but if they are supplied, they
  # are silently recorded into @init_args (for argument array) and @init_block
  # (for block, if given) instance variables, exposed via standard readers.
  # 
  def initialize *args, &block
    @init_args = args
    @init_block = block
    @recorded_messages = []
  end

  # Always true.
  # 
  def present?; true end

  # Always false.
  # 
  def blank?; false end

  # Always true.
  # 
  def respond_to? ß, *args, █ true end

  def method_missing ß, *args, &block      # :nodoc:
    @recorded_messages << [ ß, args, block ]
    return self
  end
end # class InertRecorder


class Object
  # InertRecorder constructor.
  # 
  def InertRecorder *args, &block; InertRecorder.new *args, &block end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
y_support-2.5.3 lib/y_support/misc/inert_recorder.rb
y_support-2.5.2 lib/y_support/misc/inert_recorder.rb
y_support-2.5.1 lib/y_support/misc/inert_recorder.rb