Sha256: 10055b7441c4faa5464a5b05d6e953e39bf93b2790dad7ee01c4429efe78eb82

Contents?: true

Size: 1.15 KB

Versions: 25

Compression:

Stored size: 1.15 KB

Contents

# -*- coding: utf-8 -*-
require 'y_support'

# Object, whose business is to stay local to methods. Optional signature
# provides additional level of safety in ensuring object locality. (Signature
# accessor is :signature, aliased as :σ, small Greek sigma.)
# 
class LocalObject
  attr_reader :signature
  alias σ signature

  # Optional argument signature provides additional level of safety in
  # ascertaining that the object indeed is of local origin.
  # 
  def initialize signature=caller_locations( 1, 1 )[0].label
    @signature = signature
  end

  # True if the (optional) signature matches.
  # 
  def local_object? signature=caller_locations( 1, 1 )[0].label
    signature == self.signature
  end
  alias ℓ? local_object?
end

# Object class is patched with #LocalObject (alias L!) constructor, and
# #local_object?, alias #ℓ? inquirer.
# 
class Object
  # LocalObject constructor.
  # 
  def LocalObject signature=caller_locations( 1, 1 )[0].label
    LocalObject.new signature
  end
  alias L! LocalObject

  # False for normal objects, overriden in the LocalObject class.
  # 
  def local_object? signature=nil; false end
  alias ℓ? local_object?
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
y_support-2.0.30 lib/y_support/local_object.rb
y_support-2.0.29 lib/y_support/local_object.rb
y_support-2.0.28 lib/y_support/local_object.rb
y_support-2.0.26 lib/y_support/local_object.rb
y_support-2.0.25 lib/y_support/local_object.rb
y_support-2.0.24 lib/y_support/local_object.rb
y_support-2.0.23 lib/y_support/local_object.rb
y_support-2.0.21 lib/y_support/local_object.rb
y_support-2.0.20 lib/y_support/local_object.rb
y_support-2.0.19 lib/y_support/local_object.rb
y_support-2.0.18 lib/y_support/local_object.rb
y_support-2.0.17 lib/y_support/local_object.rb
y_support-2.0.16 lib/y_support/local_object.rb
y_support-2.0.15.p1 lib/y_support/local_object.rb
y_support-2.0.15 lib/y_support/local_object.rb
y_support-2.0.14 lib/y_support/local_object.rb
y_support-2.0.13 lib/y_support/local_object.rb
y_support-2.0.11 lib/y_support/local_object.rb
y_support-2.0.10 lib/y_support/local_object.rb
y_support-2.0.9 lib/y_support/local_object.rb