ampex 0.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ampex.rb +57 -1
- metadata +18 -8
data/lib/ampex.rb
CHANGED
@@ -24,6 +24,62 @@ class Metavariable < BlankSlate
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
def metavariable_precedence
|
29
|
+
@parent unless @block
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class CallByName < BlankSlate
|
34
|
+
def initialize(obj, parent=nil, name=nil, args=nil, block=nil)
|
35
|
+
@obj = obj
|
36
|
+
@parent = parent
|
37
|
+
@name = name
|
38
|
+
@args = args
|
39
|
+
@block = block
|
40
|
+
end
|
41
|
+
|
42
|
+
def method_missing(name, *args, &block)
|
43
|
+
CallByName.new(nil, self, name, args, block)
|
44
|
+
end
|
45
|
+
|
46
|
+
def unwind_callbyname(*args)
|
47
|
+
provided.map{|x| Metavariable === x ? called[x.metavariable_precedence] : x}
|
48
|
+
if @parent
|
49
|
+
@parent.unwind_callbyname(*args).send(@name, *CallByName.merge_args(@args, args), &@block)
|
50
|
+
else
|
51
|
+
@obj
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_proc
|
56
|
+
if @parent
|
57
|
+
lambda { |*args| unwind_callbyname(*args) }
|
58
|
+
else
|
59
|
+
lambda { |*args| @obj }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.merge_args(provided, called)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
class Regexp
|
69
|
+
def [](obj)
|
70
|
+
CallByName.new(obj)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
module Kernel
|
75
|
+
def X
|
76
|
+
Metavariable.new(0)
|
77
|
+
end
|
27
78
|
end
|
28
79
|
|
29
|
-
|
80
|
+
K = Metavariable.new(0)
|
81
|
+
V = Metavariable.new(1)
|
82
|
+
W = Regexp.new""
|
83
|
+
X =
|
84
|
+
Y = Metavariable.new(1)
|
85
|
+
Z = Metavariable.new(2)
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ampex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 9
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
|
-
-
|
9
|
-
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Conrad Irwin
|
@@ -14,10 +14,22 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-17 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: blankslate
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
21
33
|
description: Why would you want to write { |x| x['one'] } when you can write &X['one'], why indeed.
|
22
34
|
email: conrad.irwin@gmail.com
|
23
35
|
executables: []
|
@@ -44,7 +56,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
56
|
requirements:
|
45
57
|
- - ">="
|
46
58
|
- !ruby/object:Gem::Version
|
47
|
-
hash: 3
|
48
59
|
segments:
|
49
60
|
- 0
|
50
61
|
version: "0"
|
@@ -53,7 +64,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
64
|
requirements:
|
54
65
|
- - ">="
|
55
66
|
- !ruby/object:Gem::Version
|
56
|
-
hash: 3
|
57
67
|
segments:
|
58
68
|
- 0
|
59
69
|
version: "0"
|