scaruby 0.0.5 → 0.0.6
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/lib/scaruby/concurrent.rb +46 -46
- data/lib/scaruby/core_ext/enumerable.rb +1 -1
- data/lib/scaruby/core_ext/hash.rb +1 -1
- data/lib/scaruby/io.rb +62 -62
- data/lib/scaruby/map.rb +141 -141
- data/lib/scaruby/option.rb +46 -38
- data/lib/scaruby/seq.rb +395 -395
- data/lib/scaruby/version.rb +1 -1
- data/lib/scaruby.rb +59 -58
- data/scaruby.gemspec +23 -23
- data/spec/scaruby/converter_spec.rb +27 -27
- data/spec/scaruby/core_ext/enumerable_spec.rb +288 -288
- data/spec/scaruby/core_ext/hash_spec.rb +92 -92
- data/spec/scaruby/io_spec.rb +56 -56
- data/spec/scaruby/map_spec.rb +117 -117
- data/spec/scaruby/option_spec.rb +50 -43
- data/spec/scaruby/seq_spec.rb +301 -301
- data/spec/scaruby_spec.rb +32 -32
- metadata +19 -27
data/lib/scaruby/version.rb
CHANGED
data/lib/scaruby.rb
CHANGED
@@ -1,58 +1,59 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'scaruby/appliable_proc'
|
4
|
-
require 'scaruby/concurrent'
|
5
|
-
require 'scaruby/converter'
|
6
|
-
require 'scaruby/io'
|
7
|
-
require 'scaruby/map'
|
8
|
-
require 'scaruby/exception'
|
9
|
-
require 'scaruby/option'
|
10
|
-
require 'scaruby/seq'
|
11
|
-
require 'scaruby/version'
|
12
|
-
|
13
|
-
module Scaruby
|
14
|
-
|
15
|
-
module Commons
|
16
|
-
|
17
|
-
def assert_type(v, *types)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
else
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
input
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
include Scaruby
|
56
|
-
include Scaruby::
|
57
|
-
|
58
|
-
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'scaruby/appliable_proc'
|
4
|
+
require 'scaruby/concurrent'
|
5
|
+
require 'scaruby/converter'
|
6
|
+
require 'scaruby/io'
|
7
|
+
require 'scaruby/map'
|
8
|
+
require 'scaruby/exception'
|
9
|
+
require 'scaruby/option'
|
10
|
+
require 'scaruby/seq'
|
11
|
+
require 'scaruby/version'
|
12
|
+
|
13
|
+
module Scaruby
|
14
|
+
|
15
|
+
module Commons
|
16
|
+
|
17
|
+
def assert_type(v, *types)
|
18
|
+
unless v.nil?
|
19
|
+
found = types.inject(false) { |found, type|
|
20
|
+
if found
|
21
|
+
true
|
22
|
+
else
|
23
|
+
v.is_a?(type)
|
24
|
+
end
|
25
|
+
}
|
26
|
+
unless found
|
27
|
+
raise AssertionError,
|
28
|
+
"The type of `#{v}` should be whichever of [#{types.join(', ')}] but actually #{v.class}."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
module Predef
|
36
|
+
|
37
|
+
def assert(assertion)
|
38
|
+
unless assertion
|
39
|
+
raise AssertionError, 'Assertion failed'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def println(any)
|
44
|
+
puts any.to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
def read_line
|
48
|
+
input = readline
|
49
|
+
input.sub(/\r?\n/, '')
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
include Scaruby
|
56
|
+
include Scaruby::Commons
|
57
|
+
include Scaruby::Predef
|
58
|
+
|
59
|
+
|
data/scaruby.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "scaruby/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name
|
7
|
-
s.version
|
8
|
-
s.authors
|
9
|
-
s.email
|
10
|
-
s.homepage
|
11
|
-
s.summary
|
12
|
-
s.description = %q{Scala API in Ruby}
|
13
|
-
|
14
|
-
s.rubyforge_project = "scaruby"
|
15
|
-
|
16
|
-
s.files
|
17
|
-
s.test_files
|
18
|
-
s.executables
|
19
|
-
s.require_paths = ["lib"]
|
20
|
-
|
21
|
-
s.required_ruby_version = '>= 1.9.2'
|
22
|
-
|
23
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "scaruby/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "scaruby"
|
7
|
+
s.version = Scaruby::VERSION
|
8
|
+
s.authors = ["Kazuhiro Sera"]
|
9
|
+
s.email = ["seratch@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/seratch/scaruby"
|
11
|
+
s.summary = %q{Scala API in Ruby}
|
12
|
+
s.description = %q{Scala API in Ruby}
|
13
|
+
|
14
|
+
s.rubyforge_project = "scaruby"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.required_ruby_version = '>= 1.9.2'
|
22
|
+
|
23
|
+
end
|
@@ -1,27 +1,27 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'scaruby/converter'
|
4
|
-
|
5
|
-
describe Enumerable do
|
6
|
-
it 'has #to_scaruby' do
|
7
|
-
[1,2,3].to_scaruby.filter {|e| e > 1 }.to_a.should eq([2,3])
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe Hash do
|
12
|
-
it 'has #to_scaruby' do
|
13
|
-
{123=>'abc',2=>'b',34=>'cd'}.to_scaruby.filter {|k,v|
|
14
|
-
k.to_s.length == 1
|
15
|
-
}.to_hash.should eq({2=>'b'})
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe Object do
|
20
|
-
it 'has #to_option' do
|
21
|
-
'abc'.to_option.is_defined.should eq(true)
|
22
|
-
'abc'.to_option.get_or_else('zzz').should eq('abc')
|
23
|
-
nil.to_option.is_defined.should eq(false)
|
24
|
-
nil.to_option.get_or_else('zzz').should eq('zzz')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'scaruby/converter'
|
4
|
+
|
5
|
+
describe Enumerable do
|
6
|
+
it 'has #to_scaruby' do
|
7
|
+
[1, 2, 3].to_scaruby.filter { |e| e > 1 }.to_a.should eq([2, 3])
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Hash do
|
12
|
+
it 'has #to_scaruby' do
|
13
|
+
{123 => 'abc', 2 => 'b', 34 => 'cd'}.to_scaruby.filter { |k, v|
|
14
|
+
k.to_s.length == 1
|
15
|
+
}.to_hash.should eq({2 => 'b'})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe Object do
|
20
|
+
it 'has #to_option' do
|
21
|
+
'abc'.to_option.is_defined.should eq(true)
|
22
|
+
'abc'.to_option.get_or_else('zzz').should eq('abc')
|
23
|
+
nil.to_option.is_defined.should eq(false)
|
24
|
+
nil.to_option.get_or_else('zzz').should eq('zzz')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|