OLD | NEW |
1 # Protocol Buffers - Google's data interchange format | 1 # Protocol Buffers - Google's data interchange format |
2 # Copyright 2008 Google Inc. All rights reserved. | 2 # Copyright 2008 Google Inc. All rights reserved. |
3 # https://developers.google.com/protocol-buffers/ | 3 # https://developers.google.com/protocol-buffers/ |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
7 # met: | 7 # met: |
8 # | 8 # |
9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 # | 67 # |
68 # NOTE: using delegators rather than method_missing to make the | 68 # NOTE: using delegators rather than method_missing to make the |
69 # relationship explicit instead of implicit | 69 # relationship explicit instead of implicit |
70 def_delegators :to_ary, | 70 def_delegators :to_ary, |
71 :&, :*, :-, :'<=>', | 71 :&, :*, :-, :'<=>', |
72 :assoc, :bsearch, :bsearch_index, :combination, :compact, :count, | 72 :assoc, :bsearch, :bsearch_index, :combination, :compact, :count, |
73 :cycle, :dig, :drop, :drop_while, :eql?, :fetch, :find_index, :flatten, | 73 :cycle, :dig, :drop, :drop_while, :eql?, :fetch, :find_index, :flatten, |
74 :include?, :index, :inspect, :join, | 74 :include?, :index, :inspect, :join, |
75 :pack, :permutation, :product, :pretty_print, :pretty_print_cycle, | 75 :pack, :permutation, :product, :pretty_print, :pretty_print_cycle, |
76 :rassoc, :repeated_combination, :repeated_permutation, :reverse, | 76 :rassoc, :repeated_combination, :repeated_permutation, :reverse, |
77 :rindex, :rotate, :sample, :shuffle, :shelljoin, :slice, | 77 :rindex, :rotate, :sample, :shuffle, :shelljoin, |
78 :to_s, :transpose, :uniq, :| | 78 :to_s, :transpose, :uniq, :| |
79 | 79 |
80 | 80 |
81 def first(n=nil) | 81 def first(n=nil) |
82 n ? self[0..n] : self[0] | 82 n ? self[0..n] : self[0] |
83 end | 83 end |
84 | 84 |
85 | 85 |
86 def last(n=nil) | 86 def last(n=nil) |
87 n ? self[(self.size-n-1)..-1] : self[-1] | 87 n ? self[(self.size-n-1)..-1] : self[-1] |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 166 |
167 # propagates changes made by user of enumerator back to the original repea
ted field. | 167 # propagates changes made by user of enumerator back to the original repea
ted field. |
168 # This only applies in cases where the calling function which created the
enumerator, | 168 # This only applies in cases where the calling function which created the
enumerator, |
169 # such as #sort!, modifies itself rather than a new array, such as #sort | 169 # such as #sort!, modifies itself rather than a new array, such as #sort |
170 class ProxyingEnumerator < Struct.new(:repeated_field, :external_enumerato
r) | 170 class ProxyingEnumerator < Struct.new(:repeated_field, :external_enumerato
r) |
171 def each(*args, &block) | 171 def each(*args, &block) |
172 results = [] | 172 results = [] |
173 external_enumerator.each_with_index do |val, i| | 173 external_enumerator.each_with_index do |val, i| |
174 result = yield(val) | 174 result = yield(val) |
175 results << result | 175 results << result |
176 #nil means no change occured from yield; usually occurs when #to_a i
s called | 176 #nil means no change occurred from yield; usually occurs when #to_a
is called |
177 if result | 177 if result |
178 repeated_field[i] = result if result != val | 178 repeated_field[i] = result if result != val |
179 end | 179 end |
180 end | 180 end |
181 results | 181 results |
182 end | 182 end |
183 end | 183 end |
184 | 184 |
185 | 185 |
186 end | 186 end |
187 end | 187 end |
188 end | 188 end |
OLD | NEW |