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

#initialize(subject, ancestor) ⇒ As

Returns a new instance of As



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

#method_missing(sym, *args, &blk) ⇒ Object (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

._newObject (private)



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

alias_method :_new, :new

.cacheObject (private)



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

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

.new(subject, ancestor) ⇒ Object



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

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