ruby_list_comprehension 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ruby_list_comprehension.rb +7 -27
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7a9ebff10a291db9bcaff1f0b5121098a7a754e8c1567ae272f37e346546f09c
|
|
4
|
+
data.tar.gz: 4182e27d98a1c0030acf308d5a97410eda1b63fc9aa3ba3e1a27bc715c13432b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 45921c152d9f7c24972a99da58576e85e4d0ad4a5251b6e23fcf01b78977c22294a8177771b2590b9f882a7ad871c8aa4ab5e40dcb23527a9f6fbd3409b6ce0f
|
|
7
|
+
data.tar.gz: 8449cbcbafdcbeb27d7c937305cf6c1fb7f46a8869b294acce3b4b46560fa0936b65c8e14b8397e67f70d8758a4f93117eab577c6f582873c56cad25eb115246
|
|
@@ -10,6 +10,8 @@ class ListComprehension
|
|
|
10
10
|
def initialize
|
|
11
11
|
@version = RUBY_VERSION
|
|
12
12
|
@c = ->x {
|
|
13
|
+
return [] if x == ""
|
|
14
|
+
raise 'syntax error in list comprehension' if x.length < 10
|
|
13
15
|
arr = x.split
|
|
14
16
|
begin
|
|
15
17
|
if arr[3][-1] == ';' || arr[4][0] == ';'
|
|
@@ -28,19 +30,20 @@ class ListComprehension
|
|
|
28
30
|
if_condition = arr.include?('if') ? arr[arr.index('if') + 1...-1] : ['true']
|
|
29
31
|
map_condition = arr[arr.index('do') + 1...(arr.index('if') || arr.index('end'))]
|
|
30
32
|
if (map_condition == [arr[1]]) && (if_condition == ['true'] || if_condition == true)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
p "no method needed"
|
|
34
|
+
res = eval(arr[3])
|
|
35
|
+
return res.is_a?(Array) ? res : [res]
|
|
33
36
|
end
|
|
34
37
|
self.class.send(:define_method,'lc') do |arr|
|
|
35
38
|
if map_condition == [arr[1]]
|
|
36
|
-
|
|
39
|
+
p 'filter'
|
|
37
40
|
return eval(iterable).filter do |x|
|
|
38
41
|
eval(if_condition.join(' '))
|
|
39
42
|
end
|
|
40
43
|
end
|
|
41
44
|
|
|
42
45
|
if if_condition == ['true'] || if_condition == true
|
|
43
|
-
|
|
46
|
+
p 'map'
|
|
44
47
|
return eval(iterable).map do |x|
|
|
45
48
|
eval(map_condition.join(' '))
|
|
46
49
|
end
|
|
@@ -60,26 +63,3 @@ class ListComprehension
|
|
|
60
63
|
}
|
|
61
64
|
end
|
|
62
65
|
end
|
|
63
|
-
require 'set'
|
|
64
|
-
l = ListComprehension.new
|
|
65
|
-
# p l['for x in 1..[1,2,3].reduce{@1+@2} do x if x end']
|
|
66
|
-
# # p l["for x in {1=>1, 2=>2} do x if x end"]
|
|
67
|
-
# p l['for x in 1..10 do x if x end']
|
|
68
|
-
# p l['for x in Set.new(1..10) do x**2 if x > 2 end']
|
|
69
|
-
# p l['for x in 1..10 do x**2 if x > 5 end'] == (1..10).filter_map{@1 ** 2 if @1 > 5}
|
|
70
|
-
# p arr = l['for x in 1..10 do x end'] == [for x in 1..10 do x end]
|
|
71
|
-
# p arr2 = l['for x in 1..10 do x ** 2 if x % 2 == 0 end'] == (1..10).filter_map{@1**2 if @1 % 2 == 0}
|
|
72
|
-
# p arr3 = l['for x in [1,2,3,4,5] do x if x % 2 == 0 end'] == [1,2,3,4,5].filter{@1 % 2 == 0}
|
|
73
|
-
# p arr7 = l['for x in 1..10 do x if x % 2 == 0 end']
|
|
74
|
-
# p arr9 = l['for x in 1..10 ; x if x % 2 == 0 end'] == (1..10).filter{@1 % 2 == 0}
|
|
75
|
-
# p arr9 = l['for x in 1..10; x if x % 2 == 0 end'] == (1..10).filter{@1 % 2 == 0}
|
|
76
|
-
#
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
# a = for x in Set.new([1,2,3]) do x**2 end
|
|
83
|
-
# Set.new([1,2,3]).filter_map(&->x{x+1 if x > 2})
|
|
84
|
-
# p a.each(&1.:p)
|
|
85
|
-
# p for x in Set.new([1,2,3]) do x**2 if x > 2 end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby_list_comprehension
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Michael
|
|
@@ -17,7 +17,7 @@ extensions: []
|
|
|
17
17
|
extra_rdoc_files: []
|
|
18
18
|
files:
|
|
19
19
|
- lib/ruby_list_comprehension.rb
|
|
20
|
-
homepage: https://
|
|
20
|
+
homepage: https://github.com/SammoMichael/Ruby_List_Comprehension
|
|
21
21
|
licenses:
|
|
22
22
|
- MIT
|
|
23
23
|
metadata: {}
|