proc_to_ast 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/proc_to_ast.rb +10 -0
- data/lib/proc_to_ast/version.rb +1 -1
- data/spec/proc_to_ast_spec.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f3724c4ba65ca104c10bbebb19d039786d27f3b
|
4
|
+
data.tar.gz: 83dd301e6bd1b425c366cd57b8861d577972f62c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 437196f743ace174ca0ad6a4fd38e3f04cd32569fadf25dd0665de55cc3332f6d4b6c2a6d2a6264381fae6e01a1ece5feee27247e91e51413718e38897736441
|
7
|
+
data.tar.gz: e9bb92c73bf93b0def19b5fb76a91ca07117c9492f8582b8482d493f208761c91fa62c861e0f783d4ea06c742f87ca13c626ff2786f6ca2cf79a3ece8dd6e7f0
|
data/lib/proc_to_ast.rb
CHANGED
@@ -109,4 +109,14 @@ class Proc
|
|
109
109
|
source
|
110
110
|
end
|
111
111
|
end
|
112
|
+
|
113
|
+
def to_raw_source(highlight: false, retry_limit: 20)
|
114
|
+
source = to_ast(retry_limit).loc.expression.source
|
115
|
+
|
116
|
+
if highlight
|
117
|
+
CodeRay.scan(source, :ruby).terminal
|
118
|
+
else
|
119
|
+
source
|
120
|
+
end
|
121
|
+
end
|
112
122
|
end
|
data/lib/proc_to_ast/version.rb
CHANGED
data/spec/proc_to_ast_spec.rb
CHANGED
@@ -125,4 +125,12 @@ describe Proc do
|
|
125
125
|
expect(fuga.to_source(highlight: true)).to eq("lambda \e[32mdo\e[0m |a|\n p(a)\n\e[32mend\e[0m")
|
126
126
|
end
|
127
127
|
end
|
128
|
+
|
129
|
+
describe "#to_raw_source" do
|
130
|
+
it "return original source code" do
|
131
|
+
pr = ->(a) { a + 1 }
|
132
|
+
|
133
|
+
expect(pr.to_raw_source).to eq("->(a) { a + 1 }")
|
134
|
+
end
|
135
|
+
end
|
128
136
|
end
|