jruby-scala-collections 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +36 -0
- data/lib/jruby/scala_support.rb +1 -0
- metadata +3 -3
data/README.md
CHANGED
@@ -3,6 +3,12 @@
|
|
3
3
|
A tiny interoperability library for passing JRuby/Scala collections back
|
4
4
|
and forth.
|
5
5
|
|
6
|
+
https://rubygems.org/gems/jruby-scala-collections
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
$ gem install jruby-scala-collections
|
11
|
+
|
6
12
|
## How do you use it?
|
7
13
|
|
8
14
|
Each ```Object``` has two methods: ```#to_scala``` and ```#from_scala```.
|
@@ -17,6 +23,36 @@ Example:
|
|
17
23
|
scala_arr = scala_object.do_stuff(r_arr.to_scala)
|
18
24
|
scala_arr.from_scala
|
19
25
|
|
26
|
+
* ```Array#to_scala``` becomes ```scala.collection.mutable.Buffer```
|
27
|
+
* ```Hash#to_scala``` becomes ```scala.collection.mutable.Map```
|
28
|
+
* ```Set#to_scala``` becomes ```scala.collection.mutable.Set```
|
29
|
+
|
30
|
+
Take node that even collections inside collections are wrapped:
|
31
|
+
|
32
|
+
> a = [1,[2,3],{4=>5}].to_scala
|
33
|
+
=> #<Java::JrubyCollection::ListWrapper:0x768bdb>
|
34
|
+
> a.apply(1)
|
35
|
+
=> #<Java::JrubyCollection::ListWrapper:0x884ab9>
|
36
|
+
> a.apply(2)
|
37
|
+
=> #<Java::JrubyCollection::MapWrapper:0x1bb605>
|
38
|
+
|
39
|
+
From Scala side Ruby primitives are converted using default JRuby conversions
|
40
|
+
that are listed in https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby section
|
41
|
+
"Conversion of Types".
|
42
|
+
|
43
|
+
So if you expect Array of Fixnums coming to your scala method, it should accept:
|
44
|
+
|
45
|
+
// Either
|
46
|
+
def scalaMethod(args: collection.mutable.Buffer[Long])
|
47
|
+
// Or
|
48
|
+
def scalaMethod(args: collection.Seq[Long])
|
49
|
+
|
50
|
+
It also adds ```#Some``` and ```None``` so you could pass values to Scala
|
51
|
+
methods:
|
52
|
+
|
53
|
+
scala_object.set(Some(3))
|
54
|
+
scala_object.get(None)
|
55
|
+
|
20
56
|
## Disclaimer
|
21
57
|
|
22
58
|
This library was written by Artūras 'arturaz' Šlajus for personal
|
data/lib/jruby/scala_support.rb
CHANGED
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: jruby-scala-collections
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Artūras Šlajus
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-23 00:00:00.
|
12
|
+
date: 2012-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Interoperability layer for passing JRuby & Scala collections back and forth. See README.md for more info.
|
15
15
|
email: arturas.slajus@gmail.com
|
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
40
|
none: false
|
41
41
|
requirements: []
|
42
42
|
rubyforge_project:
|
43
|
-
rubygems_version: 1.8.
|
43
|
+
rubygems_version: 1.8.24
|
44
44
|
signing_key:
|
45
45
|
specification_version: 3
|
46
46
|
summary: Compiled against JRuby 1.6.7/Scala 2.9.2
|