Class: JRClj

Inherits:
Object
  • Object
show all
Defined in:
lib/jrclj.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*pkgs) ⇒ JRClj

Returns a new instance of JRClj.



7
8
9
10
11
12
13
14
15
16
# File 'lib/jrclj.rb', line 7

def initialize *pkgs
  @mappings = {}
  @ns_map  = RT.var "clojure.core", "ns-map"
  @symbol  = RT.var "clojure.core", "symbol"
  @require = RT.var "clojure.core", "require"
  _import "clojure.core"
  pkgs.each do |pkg|
    _import pkg
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



43
44
45
# File 'lib/jrclj.rb', line 43

def method_missing symbol, *args
  _invoke symbol, *args
end

Class Method Details

.persistent_map(entries = []) ⇒ Object



47
48
49
# File 'lib/jrclj.rb', line 47

def self.persistent_map entries=[]
  Java::ClojureLang::PersistentArrayMap.new entries.to_java
end

Instance Method Details

#_alias(new, old) ⇒ Object



39
40
41
# File 'lib/jrclj.rb', line 39

def _alias new, old
  @mappings[new] = @mappings[old]
end

#_import(pkg_name, sym = nil, sym_alias = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jrclj.rb', line 18

def _import pkg_name, sym=nil, sym_alias=nil
  @require.invoke @symbol.invoke(pkg_name)
  if sym
    sym_alias ||= sym
    @mappings[sym_alias] = RT.var pkg_name, sym
    return
  end
  pkg = @symbol.invoke pkg_name
  @ns_map.invoke(pkg).each do |sym,var|
    @mappings[sym.to_s] = var
  end
end

#_invoke(m, *args) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/jrclj.rb', line 31

def _invoke m, *args
  fun = @mappings[m.to_s] || @mappings[m.to_s.gsub "_", "-"]
  unless fun
    raise "Error, no current binding for symbol=#{m}"
  end
  fun.invoke(*args)
end