Class: As

Inherits:
Object show all
Defined in:
lib/core/facets/kernel/as.rb

Overview

Support class for Kernel#as.

TODO: Deprecate this and use Functor (HigherOrderMessage) instead ?

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (As) initialize(subject, ancestor)



105
106
107
108
# File 'lib/core/facets/kernel/as.rb', line 105

def initialize(subject, ancestor)
  @subject = subject
  @ancestor = ancestor
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(sym, *args, &blk) (private)



112
113
114
# File 'lib/core/facets/kernel/as.rb', line 112

def method_missing(sym, *args, &blk)
  @ancestor.instance_method(sym).bind(@subject).call(*args,&blk)
end

Class Method Details

+ (Object) _new (private)



88
# File 'lib/core/facets/kernel/as.rb', line 88

alias_method :_new, :new

+ (Object) cache (private)



94
95
96
# File 'lib/core/facets/kernel/as.rb', line 94

def cache
  @cache ||= Hash.new{|h,k| h[k]={} }
end

+ (Object) new(subject, ancestor)



90
91
92
# File 'lib/core/facets/kernel/as.rb', line 90

def new(subject, ancestor)
  cache[subject][ancestor] ||= _new(subject, ancestor)
end