Module: Kernel

Defined in:
lib/vapir-common/external/core_extensions.rb

Class Method Summary collapse

Class Method Details

.warn_with_caller(message) ⇒ Object



62
63
64
# File 'lib/vapir-common/external/core_extensions.rb', line 62

def warn_with_caller(message)
  Kernel.warn "#{message}\ncalled from: #{caller[1..-1].map{|c|"\n\t"+c}.join('')}"
end

.ycombObject

this is the Y-combinator, which allows anonymous recursive functions. for a simple example, to define a recursive function to return the length of an array:

length = ycomb do |len|
  proc{|list| list == [] ? 0 : len.call(list[1..-1]) }
end

see secure.wikimedia.org/wikipedia/en/wiki/Fixed_point_combinator#Y_combinator and chapter 9 of the little schemer, available as the sample chapter at www.ccs.neu.edu/home/matthias/BTLS/



57
58
59
# File 'lib/vapir-common/external/core_extensions.rb', line 57

def ycomb
  proc{|f| f.call(f) }.call(proc{|f| yield proc{|*x| f.call(f).call(*x) } })
end