scaruby 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/lib/scaruby/appliable_proc.rb +3 -0
- data/lib/scaruby/core_ext.rb +1 -0
- data/lib/scaruby/core_ext/proc.rb +18 -0
- data/lib/scaruby/function.rb +17 -0
- data/lib/scaruby/version.rb +1 -1
- data/spec/scaruby/appliable_proc_spec.rb +28 -0
- data/spec/scaruby/core_ext/proc_spec.rb +29 -0
- metadata +9 -3
data/.gitignore
CHANGED
data/lib/scaruby/core_ext.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'scaruby/function'
|
4
|
+
|
5
|
+
class Proc
|
6
|
+
|
7
|
+
alias_method :apply, :call
|
8
|
+
|
9
|
+
def method_missing(name, *args, &block)
|
10
|
+
if self.is_a? Scaruby::Function
|
11
|
+
self.send(name, *args, &block)
|
12
|
+
else
|
13
|
+
self.extend(Scaruby::Function).send(name, *args, &block)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'scaruby/appliable_proc'
|
4
|
+
|
5
|
+
module Scaruby
|
6
|
+
module Function
|
7
|
+
|
8
|
+
def compose(g)
|
9
|
+
Proc.new { |*args| self.call(g.call(*args)) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def and_then(g)
|
13
|
+
Proc.new { |*args| g.call(self.call(*args)) }
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/scaruby/version.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'scaruby/appliable_proc'
|
4
|
+
|
5
|
+
describe Scaruby::AppliableProc do
|
6
|
+
|
7
|
+
up = Scaruby::AppliableProc.new { |v| v.upcase }
|
8
|
+
up_join = Scaruby::AppliableProc.new { |a, b| "#{a.upcase} #{b.upcase}" }
|
9
|
+
hello = Scaruby::AppliableProc.new { "Hello!" }
|
10
|
+
twice = Scaruby::AppliableProc.new { |v| "#{v} #{v}" }
|
11
|
+
|
12
|
+
it "should have #apply" do
|
13
|
+
hello.apply().should ==("Hello!")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have #compose" do
|
17
|
+
twice.compose(hello).apply().should ==("Hello! Hello!")
|
18
|
+
twice.compose(up).apply("Hello!").should ==("HELLO! HELLO!")
|
19
|
+
twice.compose(up_join).apply("Hello,", "World!").should ==("HELLO, WORLD! HELLO, WORLD!")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should have #and_then" do
|
23
|
+
hello.and_then(twice).apply().should ==("Hello! Hello!")
|
24
|
+
up.and_then(twice).apply("Hello!").should ==("HELLO! HELLO!")
|
25
|
+
up_join.and_then(twice).apply("Hello,", "World!").should ==("HELLO, WORLD! HELLO, WORLD!")
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'scaruby/core_ext'
|
4
|
+
|
5
|
+
describe Proc do
|
6
|
+
|
7
|
+
up = Proc.new { |v| v.upcase }
|
8
|
+
up_join = Proc.new { |a, b| "#{a.upcase} #{b.upcase}" }
|
9
|
+
hello = Proc.new { "Hello!" }
|
10
|
+
twice = Proc.new { |v| "#{v} #{v}" }
|
11
|
+
|
12
|
+
it "should have #apply" do
|
13
|
+
hello.apply().should ==("Hello!")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have #compose" do
|
17
|
+
twice.compose(hello).apply().should ==("Hello! Hello!")
|
18
|
+
twice.compose(up).apply("Hello!").should ==("HELLO! HELLO!")
|
19
|
+
twice.compose(up_join).apply("Hello,", "World!").should ==("HELLO, WORLD! HELLO, WORLD!")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should have #and_then" do
|
23
|
+
hello.and_then(twice).apply().should ==("Hello! Hello!")
|
24
|
+
up.and_then(twice).apply("Hello!").should ==("HELLO! HELLO!")
|
25
|
+
up_join.and_then(twice).apply("Hello,", "World!").should ==("HELLO, WORLD! HELLO, WORLD!")
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scaruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-10 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Scala API in Ruby
|
15
15
|
email:
|
@@ -30,7 +30,9 @@ files:
|
|
30
30
|
- lib/scaruby/core_ext.rb
|
31
31
|
- lib/scaruby/core_ext/enumerable.rb
|
32
32
|
- lib/scaruby/core_ext/hash.rb
|
33
|
+
- lib/scaruby/core_ext/proc.rb
|
33
34
|
- lib/scaruby/exception.rb
|
35
|
+
- lib/scaruby/function.rb
|
34
36
|
- lib/scaruby/io.rb
|
35
37
|
- lib/scaruby/map.rb
|
36
38
|
- lib/scaruby/option.rb
|
@@ -38,10 +40,12 @@ files:
|
|
38
40
|
- lib/scaruby/version.rb
|
39
41
|
- readme.md
|
40
42
|
- scaruby.gemspec
|
43
|
+
- spec/scaruby/appliable_proc_spec.rb
|
41
44
|
- spec/scaruby/concurrent_spec.rb
|
42
45
|
- spec/scaruby/converter_spec.rb
|
43
46
|
- spec/scaruby/core_ext/enumerable_spec.rb
|
44
47
|
- spec/scaruby/core_ext/hash_spec.rb
|
48
|
+
- spec/scaruby/core_ext/proc_spec.rb
|
45
49
|
- spec/scaruby/io_spec.rb
|
46
50
|
- spec/scaruby/map_spec.rb
|
47
51
|
- spec/scaruby/option_spec.rb
|
@@ -67,15 +71,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
71
|
version: '0'
|
68
72
|
requirements: []
|
69
73
|
rubyforge_project: scaruby
|
70
|
-
rubygems_version: 1.8.
|
74
|
+
rubygems_version: 1.8.24
|
71
75
|
signing_key:
|
72
76
|
specification_version: 3
|
73
77
|
summary: Scala API in Ruby
|
74
78
|
test_files:
|
79
|
+
- spec/scaruby/appliable_proc_spec.rb
|
75
80
|
- spec/scaruby/concurrent_spec.rb
|
76
81
|
- spec/scaruby/converter_spec.rb
|
77
82
|
- spec/scaruby/core_ext/enumerable_spec.rb
|
78
83
|
- spec/scaruby/core_ext/hash_spec.rb
|
84
|
+
- spec/scaruby/core_ext/proc_spec.rb
|
79
85
|
- spec/scaruby/io_spec.rb
|
80
86
|
- spec/scaruby/map_spec.rb
|
81
87
|
- spec/scaruby/option_spec.rb
|