lambda_driver 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # LambdaDriver [![Build Status](https://travis-ci.org/yuroyoro/lambda_driver.png)](https://travis-ci.org/yuroyoro/lambda_driver)
1
+ # LambdaDriver
2
2
 
3
3
  虚弦斥力場生成システム
4
4
 
@@ -20,6 +20,10 @@ LambdaDriver drives your code more functional.
20
20
  - [project page](http://yuroyoro.github.com/lambda_driver/)
21
21
  - [rubygems.org](https://rubygems.org/gems/lambda_driver)
22
22
 
23
+ ## Build status
24
+
25
+ [![Build Status](https://travis-ci.org/yuroyoro/lambda_driver.png)](https://travis-ci.org/yuroyoro/lambda_driver)
26
+
23
27
  ## Installation
24
28
 
25
29
  Add this line to your application's Gemfile:
@@ -135,18 +139,35 @@ This method is aliased as `~@`.
135
139
 
136
140
  ### Symbol extensions
137
141
  - to_method
142
+ - to_method_with_args
138
143
 
139
144
  #### Symbol#to_method
140
145
 
141
- Symbol#to_method generates a function that extract Method object from given arguments.
146
+ Symbol#to_method generates a function that extract Method object from given argument.
142
147
  This method is aliased as `-@`.
143
148
 
144
149
  ```ruby
145
150
  (-:index).call("foobarbaz") # => #<Method: String#index>
146
- (-:index).call("foobarbaz").call("bar") # => 3 (== "foobarbaz".index(3) )
151
+ (-:index).call("foobarbaz").call("bar") # => 3 (== "foobarbaz".index("bar") )
147
152
 
148
153
  -:index < "foobarbaz" # => #<Method: String#index>
149
- -:index < "foobarbaz" < "bar" # => 3 (== "foobarbaz".index(3) )
154
+ -:index < "foobarbaz" < "bar" # => 3 (== "foobarbaz".index("bar") )
155
+ ```
156
+
157
+ #### Symbol#to_method_with_args
158
+
159
+ Symbol#to_method_with_args generates a function that extract Method object from given object,
160
+ and returns function is partially applied parameters by passed arguments.
161
+ It is same as Symbol#to_method with Proc#with_args.
162
+
163
+ This method is aliased as `&`.
164
+
165
+ ```ruby
166
+ :index.to_method_with_args("bar") # => #<Proc:0x007ffef4886ff8
167
+ :index.to_method_with_args("bar").call("foobarbaz") # => 3 (== "foobarbaz".index("bar") )
168
+
169
+ :index & "bar" # => #<Proc:0x007ffef4886ff8
170
+ :index & "bar" < "foobarbaz" # => 3 (== "foobarbaz".index("bar") )
150
171
  ```
151
172
 
152
173
  ### Class extensions
@@ -162,7 +183,7 @@ This method is aliased as `-@`.
162
183
  ```ruby
163
184
  String / :index # => #<UnboundMethod: String#index>
164
185
  String / :index < "foobarbaz" # => #<Method: String#index>
165
- String / :index < "foobarbaz" < 3 # => 3 (== "foobarbaz".index(3) )
186
+ String / :index < "foobarbaz" < 3 # => 3 (== "foobarbaz".index("bar") )
166
187
  ```
167
188
 
168
189
  ### Combinators
@@ -170,7 +191,7 @@ This method is aliased as `-@`.
170
191
  - ski combinator
171
192
 
172
193
  ### Object extensions
173
- - obj.ap(|>)
194
+ - obj.revapply(|>)
174
195
  - obj._
175
196
  - obj.disjunction(f)
176
197
 
@@ -190,7 +211,7 @@ Object#_ is shortcut to quickly extract Method object.
190
211
 
191
212
  ```ruby
192
213
  "foobarbaz"._.index # => #<Method: String#index>
193
- "foobarbaz"._.index < "bar" # => 3 (== "foobarbaz".index(3) )
214
+ "foobarbaz"._.index < "bar" # => 3 (== "foobarbaz".index("bar") )
194
215
 
195
216
  2._(:>=) # => #<Method: Fixnum#>=>
196
217
  [1, 2, 3].select(&2._(:>=)) # => [1, 2]( = [1, 2].select{|n| 2 >= n})
@@ -5,6 +5,10 @@ class Symbol
5
5
  def to_method
6
6
  lambda{|obj| obj._(self) }
7
7
  end
8
-
9
8
  alias_method :-@, :to_method
9
+
10
+ def to_method_with_args(*args)
11
+ lambda{|obj| obj._(self).call(*args) }
12
+ end
13
+ alias_method :&, :to_method_with_args
10
14
  end
@@ -1,3 +1,3 @@
1
1
  module LambdaDriver
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
data/spec/symbol_spec.rb CHANGED
@@ -75,12 +75,36 @@ describe Symbol do
75
75
  subject.call(obj).call("bar").should == obj.method(:index).call("bar")
76
76
  }
77
77
 
78
- it('-:symbol.to_method.call(obj) should returns Method'){
78
+ it('(-:symbol).call(obj) should returns Method'){
79
79
  (-:index).call(obj).should be_a_kind_of Method
80
80
  }
81
81
 
82
- it('-:symbol.to_method.call(obj).call(x) should be obj.method(symbol).call(x)'){
82
+ it('(-:symbol).call(obj).call(x) should be obj.method(symbol).call(x)'){
83
83
  (-:index).call(obj).call("bar").should == obj.method(:index).call("bar")
84
84
  }
85
+
86
+ it('-:symbol < obj < x should be obj.method(symbol).call(x)'){
87
+ (-:index < obj <"bar").should == obj.method(:index).call("bar")
88
+ }
89
+ end
90
+
91
+ describe '#to_method_with_args' do
92
+ subject { :index.to_method_with_args("bar") }
93
+
94
+ let(:obj) { "foobarbaz" }
95
+
96
+ it { should be_a_kind_of Proc }
97
+
98
+ it('symbol.to_method_with_args(x).call(obj) should be obj.method(symbol).call(x)'){
99
+ subject.call(obj).should == obj.method(:index).call("bar")
100
+ }
101
+
102
+ it('(:symbol & x).call(obj) should be obj.method(symbol).call(x)'){
103
+ (:index & 'bar').call(obj).should == obj.method(:index).call("bar")
104
+ }
105
+
106
+ it('(:symbol & x <obj) should be obj.method(symbol).call(x)'){
107
+ (:index & 'bar' < obj).should == obj.method(:index).call("bar")
108
+ }
85
109
  end
86
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lambda_driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-03-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70234094961220 !ruby/object:Gem::Requirement
16
+ requirement: &70302147613760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70234094961220
24
+ version_requirements: *70302147613760
25
25
  description: Drives your code more functioal!
26
26
  email:
27
27
  - ozaki@yuroyoro.com
@@ -74,18 +74,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
74
  - - ! '>='
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
- segments:
78
- - 0
79
- hash: 926401567287214801
80
77
  required_rubygems_version: !ruby/object:Gem::Requirement
81
78
  none: false
82
79
  requirements:
83
80
  - - ! '>='
84
81
  - !ruby/object:Gem::Version
85
82
  version: '0'
86
- segments:
87
- - 0
88
- hash: 926401567287214801
89
83
  requirements: []
90
84
  rubyforge_project:
91
85
  rubygems_version: 1.8.10