rfunk 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c7fa7d2d0ae8bb59de9d14f9393c7fc99c9225e
4
- data.tar.gz: 617c897cd4843dd3ef0782b40f20c70edd4ecf7d
3
+ metadata.gz: c1093410c5b9f09c2d27a51264793c2b018a6591
4
+ data.tar.gz: 09c356f3da1466a01486c6dc3dc164f392616e5e
5
5
  SHA512:
6
- metadata.gz: 036a43078df1545a68c123d85b53b4800009c1a7f4242e2959aa288925fa74b5b5df213243b883557db40d64703c0c0e3ba24d18481aee59a0836233f838300a
7
- data.tar.gz: c824e1f69c3dff059959e22f830aa886d06e822648afdcc8c659612b2cb9a066a97ecf0ca749a7a84867fda7982480252b06d153694746c2c929e66e5b4fdcc4
6
+ metadata.gz: af3cf4a13a0a8e29f13879b8d24cbe9dd260c84f28773105cbfc6d484027d0a4c38c96107e7e0976f066c4ed72542d7b9a5ca56b2a5cabf6f6a18cdabfa8adb7
7
+ data.tar.gz: e7013c2584a0971ea445e798df3c85ea50feec45b061f75a81789c4e33332872c7a406a6960445f262cdfc6c43c9f08f2577fd9c702df4e9ed525f2b930dbd05
@@ -1,9 +1,8 @@
1
1
  module RFunk
2
2
  module Attribute
3
- include RFunk::Variable
4
-
5
3
  def self.included(base)
6
4
  base.extend(ClassMethods)
5
+ base.extend(RFunk::AttributeFunction)
7
6
  end
8
7
 
9
8
  def initialize(options = {})
@@ -0,0 +1,11 @@
1
+ module RFunk
2
+ module AttributeFunction
3
+ def fun(method_name, &block)
4
+ lambda = lambda { |*args|
5
+ block.call(Function.new, *args)
6
+ }
7
+
8
+ define_method method_name, &lambda
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ module RFunk
2
+ class Function
3
+ def initialize
4
+ @variables = {}
5
+ end
6
+
7
+ def var(options)
8
+ if options.is_a?(Hash)
9
+ if variables.empty?
10
+ self.variables = options
11
+ else
12
+ ErrorChecking.new.raise_immutable(options, variables)
13
+ self.variables = variables.merge(options)
14
+ end
15
+ else
16
+ Some(Some(variables)[options])
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ attr_accessor :variables
23
+ end
24
+ end
@@ -14,12 +14,27 @@ module RFunk
14
14
  self
15
15
  end
16
16
 
17
+ def coerce(other)
18
+ [other, 0]
19
+ end
20
+
21
+ def to_str
22
+ ''
23
+ end
24
+
25
+ def to_ary
26
+ []
27
+ end
28
+
29
+ def to_hash
30
+ {}
31
+ end
32
+
17
33
  protected
18
34
 
19
35
  def enum
20
36
  []
21
37
  end
22
-
23
38
  end
24
39
 
25
40
  def None(value = nil)
@@ -1,5 +1,7 @@
1
1
  module RFunk
2
2
  class Some < Option
3
+ extend Forwardable
4
+
3
5
  def initialize(value)
4
6
  @value = value
5
7
  end
@@ -26,6 +28,18 @@ module RFunk
26
28
  value <=> other.value
27
29
  end
28
30
 
31
+ def coerce(other)
32
+ [other, value]
33
+ end
34
+
35
+ [:to_str, :to_ary, :to_hash].each { |k|
36
+ define_method(k) {
37
+ value
38
+ }
39
+ }
40
+
41
+ def_delegators :@value, :to_s, :inspect, :respond_to?
42
+
29
43
  protected
30
44
 
31
45
  def enum
data/lib/rfunk/tuple.rb CHANGED
@@ -2,6 +2,7 @@ module RFunk
2
2
  class Tuple
3
3
  def initialize(values)
4
4
  @values = values
5
+ deep_freeze
5
6
  end
6
7
 
7
8
  def value(*args)
data/lib/rfunk/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RFunk
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
data/lib/rfunk.rb CHANGED
@@ -8,7 +8,8 @@ require 'rfunk/attribute/immutable_error'
8
8
  require 'rfunk/attribute/attribute_variable'
9
9
  require 'rfunk/attribute/error_checking'
10
10
  require 'rfunk/attribute/attribute_type'
11
- require 'rfunk/attribute/variable'
11
+ require 'rfunk/attribute/function'
12
+ require 'rfunk/attribute/attribute_function'
12
13
  require 'rfunk/attribute/attribute'
13
14
  require 'rfunk/maybe/option'
14
15
  require 'rfunk/maybe/none'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Falkowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-16 00:00:00.000000000 Z
11
+ date: 2014-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ice_nine
@@ -61,13 +61,14 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - lib/rfunk.rb
63
63
  - lib/rfunk/attribute/attribute.rb
64
+ - lib/rfunk/attribute/attribute_function.rb
64
65
  - lib/rfunk/attribute/attribute_type.rb
65
66
  - lib/rfunk/attribute/attribute_variable.rb
66
67
  - lib/rfunk/attribute/error_checking.rb
68
+ - lib/rfunk/attribute/function.rb
67
69
  - lib/rfunk/attribute/immutable.rb
68
70
  - lib/rfunk/attribute/immutable_error.rb
69
71
  - lib/rfunk/attribute/not_found_error.rb
70
- - lib/rfunk/attribute/variable.rb
71
72
  - lib/rfunk/either/either.rb
72
73
  - lib/rfunk/either/failure.rb
73
74
  - lib/rfunk/either/success.rb
@@ -1,21 +0,0 @@
1
- module RFunk
2
- module Variable
3
- def var(options)
4
- name = "#{self.class.to_s.downcase}_#{caller_locations(1, 1)[0].label}"
5
- name = variable_name("#{name}_#{Digest::MD5.hexdigest(name)}")
6
-
7
- if options.is_a?(Hash)
8
- variable = self.instance_variable_get(name)
9
-
10
- if variable
11
- ErrorChecking.new.raise_immutable(options, variable)
12
- self.instance_variable_set(name, variable.merge(options))
13
- else
14
- self.instance_variable_set(name, options)
15
- end
16
- else
17
- Some(Some(self.instance_variable_get(name))[options])
18
- end
19
- end
20
- end
21
- end