mrubyを超漢字で動作させる
Revisão | 45e70e4dd67d4a407260f79417a48063237c9e28 (tree) |
---|---|
Hora | 2015-10-21 00:16:47 |
Autor | Seba Gamboa <me@sagm...> |
Commiter | Seba Gamboa |
Fix enumerator doc errors
@@ -6,93 +6,92 @@ | ||
6 | 6 | # A class which allows both internal and external iteration. |
7 | 7 | # |
8 | 8 | # An Enumerator can be created by the following methods. |
9 | -# - Kernel#to_enum | |
10 | -# - Kernel#enum_for | |
11 | -# - Enumerator.new | |
9 | +# - {Kernel#to_enum} | |
10 | +# - {Kernel#enum_for} | |
11 | +# - {Enumerator#initialize Enumerator.new} | |
12 | 12 | # |
13 | 13 | # Most methods have two forms: a block form where the contents |
14 | 14 | # are evaluated for each item in the enumeration, and a non-block form |
15 | 15 | # which returns a new Enumerator wrapping the iteration. |
16 | 16 | # |
17 | -# enumerator = %w(one two three).each | |
18 | -# puts enumerator.class # => Enumerator | |
17 | +# enumerator = %w(one two three).each | |
18 | +# puts enumerator.class # => Enumerator | |
19 | 19 | # |
20 | -# enumerator.each_with_object("foo") do |item, obj| | |
21 | -# puts "#{obj}: #{item}" | |
22 | -# end | |
20 | +# enumerator.each_with_object("foo") do |item, obj| | |
21 | +# puts "#{obj}: #{item}" | |
22 | +# end | |
23 | 23 | # |
24 | -# # foo: one | |
25 | -# # foo: two | |
26 | -# # foo: three | |
24 | +# # foo: one | |
25 | +# # foo: two | |
26 | +# # foo: three | |
27 | 27 | # |
28 | -# enum_with_obj = enumerator.each_with_object("foo") | |
29 | -# puts enum_with_obj.class # => Enumerator | |
28 | +# enum_with_obj = enumerator.each_with_object("foo") | |
29 | +# puts enum_with_obj.class # => Enumerator | |
30 | 30 | # |
31 | -# enum_with_obj.each do |item, obj| | |
32 | -# puts "#{obj}: #{item}" | |
33 | -# end | |
31 | +# enum_with_obj.each do |item, obj| | |
32 | +# puts "#{obj}: #{item}" | |
33 | +# end | |
34 | 34 | # |
35 | -# # foo: one | |
36 | -# # foo: two | |
37 | -# # foo: three | |
35 | +# # foo: one | |
36 | +# # foo: two | |
37 | +# # foo: three | |
38 | 38 | # |
39 | 39 | # This allows you to chain Enumerators together. For example, you |
40 | 40 | # can map a list's elements to strings containing the index |
41 | 41 | # and the element as a string via: |
42 | 42 | # |
43 | -# puts %w[foo bar baz].map.with_index { |w, i| "#{i}:#{w}" } | |
44 | -# # => ["0:foo", "1:bar", "2:baz"] | |
43 | +# puts %w[foo bar baz].map.with_index { |w, i| "#{i}:#{w}" } | |
44 | +# # => ["0:foo", "1:bar", "2:baz"] | |
45 | 45 | # |
46 | 46 | # An Enumerator can also be used as an external iterator. |
47 | 47 | # For example, Enumerator#next returns the next value of the iterator |
48 | 48 | # or raises StopIteration if the Enumerator is at the end. |
49 | 49 | # |
50 | -# e = [1,2,3].each # returns an enumerator object. | |
51 | -# puts e.next # => 1 | |
52 | -# puts e.next # => 2 | |
53 | -# puts e.next # => 3 | |
54 | -# puts e.next # raises StopIteration | |
50 | +# e = [1,2,3].each # returns an enumerator object. | |
51 | +# puts e.next # => 1 | |
52 | +# puts e.next # => 2 | |
53 | +# puts e.next # => 3 | |
54 | +# puts e.next # raises StopIteration | |
55 | 55 | # |
56 | 56 | # You can use this to implement an internal iterator as follows: |
57 | 57 | # |
58 | -# def ext_each(e) | |
59 | -# while true | |
60 | -# begin | |
61 | -# vs = e.next_values | |
62 | -# rescue StopIteration | |
63 | -# return $!.result | |
58 | +# def ext_each(e) | |
59 | +# while true | |
60 | +# begin | |
61 | +# vs = e.next_values | |
62 | +# rescue StopIteration | |
63 | +# return $!.result | |
64 | +# end | |
65 | +# y = yield(*vs) | |
66 | +# e.feed y | |
67 | +# end | |
64 | 68 | # end |
65 | -# y = yield(*vs) | |
66 | -# e.feed y | |
67 | -# end | |
68 | -# end | |
69 | 69 | # |
70 | -# o = Object.new | |
70 | +# o = Object.new | |
71 | 71 | # |
72 | -# def o.each | |
73 | -# puts yield | |
74 | -# puts yield(1) | |
75 | -# puts yield(1, 2) | |
76 | -# 3 | |
77 | -# end | |
72 | +# def o.each | |
73 | +# puts yield | |
74 | +# puts yield(1) | |
75 | +# puts yield(1, 2) | |
76 | +# 3 | |
77 | +# end | |
78 | 78 | # |
79 | -# # use o.each as an internal iterator directly. | |
80 | -# puts o.each {|*x| puts x; [:b, *x] } | |
81 | -# # => [], [:b], [1], [:b, 1], [1, 2], [:b, 1, 2], 3 | |
79 | +# # use o.each as an internal iterator directly. | |
80 | +# puts o.each {|*x| puts x; [:b, *x] } | |
81 | +# # => [], [:b], [1], [:b, 1], [1, 2], [:b, 1, 2], 3 | |
82 | 82 | # |
83 | -# # convert o.each to an external iterator for | |
84 | -# # implementing an internal iterator. | |
85 | -# puts ext_each(o.to_enum) {|*x| puts x; [:b, *x] } | |
86 | -# # => [], [:b], [1], [:b, 1], [1, 2], [:b, 1, 2], 3 | |
83 | +# # convert o.each to an external iterator for | |
84 | +# # implementing an internal iterator. | |
85 | +# puts ext_each(o.to_enum) {|*x| puts x; [:b, *x] } | |
86 | +# # => [], [:b], [1], [:b, 1], [1, 2], [:b, 1, 2], 3 | |
87 | 87 | # |
88 | 88 | # @mrbgem mruby-enumerator |
89 | 89 | class Enumerator |
90 | 90 | include Enumerable |
91 | 91 | |
92 | 92 | ## |
93 | - # call-seq: | |
94 | - # Enumerator.new(size = nil) { |yielder| ... } | |
95 | - # Enumerator.new(obj, method = :each, *args) | |
93 | + # @overload initialize(size = nil, &block) | |
94 | + # @overload initialize(obj, method = :each, *args) | |
96 | 95 | # |
97 | 96 | # Creates a new Enumerator object, which can be used as an |
98 | 97 | # Enumerable. |
@@ -101,15 +100,15 @@ class Enumerator | ||
101 | 100 | # which a "yielder" object, given as block parameter, can be used to |
102 | 101 | # yield a value by calling the +yield+ method (aliased as +<<+): |
103 | 102 | # |
104 | - # fib = Enumerator.new do |y| | |
105 | - # a = b = 1 | |
106 | - # loop do | |
107 | - # y << a | |
108 | - # a, b = b, a + b | |
103 | + # fib = Enumerator.new do |y| | |
104 | + # a = b = 1 | |
105 | + # loop do | |
106 | + # y << a | |
107 | + # a, b = b, a + b | |
108 | + # end | |
109 | 109 | # end |
110 | - # end | |
111 | 110 | # |
112 | - # p fib.take(10) # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] | |
111 | + # p fib.take(10) # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] | |
113 | 112 | # |
114 | 113 | def initialize(obj=nil, meth=:each, *args, &block) |
115 | 114 | if block_given? |
@@ -189,8 +188,7 @@ class Enumerator | ||
189 | 188 | # |
190 | 189 | # If no block is given, returns a new Enumerator. |
191 | 190 | # |
192 | - # === Example | |
193 | - # | |
191 | + # @example | |
194 | 192 | # to_three = Enumerator.new do |y| |
195 | 193 | # 3.times do |x| |
196 | 194 | # y << x |