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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbcc8eb51951a8ad12232e72f07f9899e448d080421710a5cf4fadcff9b10205
4
- data.tar.gz: 262202f315da4d52de27783d4550a629c3dd5c420e0c1b63669cf329352deec6
3
+ metadata.gz: 7a9ebff10a291db9bcaff1f0b5121098a7a754e8c1567ae272f37e346546f09c
4
+ data.tar.gz: 4182e27d98a1c0030acf308d5a97410eda1b63fc9aa3ba3e1a27bc715c13432b
5
5
  SHA512:
6
- metadata.gz: 6bbd40ed89e918b0a2561938a45e591a99e3c0606765de7c8e68a6168a390a9d2bbec2fcb8094c27d1429c11062db0fe9f0ec36514c078cb63b00e654fedb1ac
7
- data.tar.gz: c106965977c1b7f7188e3f05cce7b2758701442bf189c0447cd3bfb2a501741adfc61ee874f0bf42c56341e4acacbffa4e25195317176d69bea4ca4a95304d2a
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
- # p "no method needed"
32
- return [eval(arr[3])]
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
- # p 'filter'
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
- # p 'map'
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.2
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://rubygems.org/gems/ruby_list_comprehension
20
+ homepage: https://github.com/SammoMichael/Ruby_List_Comprehension
21
21
  licenses:
22
22
  - MIT
23
23
  metadata: {}