Method: Kernel#as
- Defined in:
- lib/core/facets/kernel/as.rb
#as(ancestor, &blk) ⇒ Object
Returns a As-functor that allows one to call any ancestor’s method directly of the given object.
class AsExample1
def x ; 1 ; end
end
class AsExample2 < AsExample1
def x ; 2 ; end
end
class AsExample3 < AsExample2
def x ; as(AsExample1).x ; end
end
AsExample1.new.x #=> 1
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/core/facets/kernel/as.rb', line 22 def as(ancestor, &blk) ##this = self r = As.new(self, ancestor) ##unless r ## r = As.cache[self][ancestor] = Functor.new do |op, *a, &b| ## ancestor.instance_method(op).bind(this).call(*a,&b) ## end ##end r.instance_eval(&blk) if block_given? #yield(r) if block_given? r end |