Module: Klam::Primitives::Interop
- Included in:
- Environment
- Defined in:
- lib/klam/primitives/interop.rb
Overview
Primitives for interoperation with the host Ruby environment. These are not official KLambda primitives.
Class Method Summary collapse
Instance Method Summary collapse
- #rb_const(name) ⇒ Object (also: #rb-const)
- #rb_send(obj, method_name, *args) ⇒ Object (also: #rb-send)
- #rb_send_block(obj, method_name, blk, *args) ⇒ Object (also: #rb-send-block)
Class Method Details
.uncurry(blk) ⇒ Object
44 45 46 47 48 |
# File 'lib/klam/primitives/interop.rb', line 44 def uncurry(blk) lambda do |*args| args.reduce(blk) { |f, x| f.call(x) } end end |
Instance Method Details
#rb_const(name) ⇒ Object Also known as: rb-const
27 28 29 30 31 32 33 |
# 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 |
#rb_send(obj, method_name, *args) ⇒ Object Also known as: rb-send
6 7 8 |
# File 'lib/klam/primitives/interop.rb', line 6 def rb_send(obj, method_name, *args) obj.send(method_name, *args) end |
#rb_send_block(obj, method_name, blk, *args) ⇒ Object Also known as: rb-send-block
12 13 14 15 16 17 18 19 20 21 22 |
# 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 |