module Klam::Primitives::Interop
Primitives
for interoperation with the host Ruby environment. These are not official KLambda primitives.
Public Class Methods
uncurry(blk)
click to toggle source
# File lib/klam/primitives/interop.rb, line 44 def uncurry(blk) lambda do |*args| args.reduce(blk) { |f, x| f.call(x) } end end
Public Instance Methods
rb_const(name)
click to toggle source
# File lib/klam/primitives/interop.rb, line 27 def rb_const(name) parts = name.to_s.split('::') parts.shift if parts.first.empty? parts.reduce(::Module) do |m, x| m.const_get(x) end end
Also aliased as: "rb-const"
rb_send(obj, method_name, *args)
click to toggle source
# File lib/klam/primitives/interop.rb, line 6 def rb_send(obj, method_name, *args) obj.send(method_name, *args) end
Also aliased as: "rb-send"
rb_send_block(obj, method_name, blk, *args)
click to toggle source
# File lib/klam/primitives/interop.rb, line 12 def rb_send_block(obj, method_name, blk, *args) if blk.instance_of?(::Symbol) # The caller won't take advantage of the currying, but we already # are tracking the curried form. This also allows for paritial # application of the named function, which could be interesting. blk = @curried_methods[blk] else blk = ::Klam::Primitives::Interop.uncurry(blk) end obj.send(method_name, *args, &blk) end
Also aliased as: "rb-send-block"