Skip to content

Commit 4f97a53

Browse files
maihaAry Borenszweig
authored and
Ary Borenszweig
committedJan 5, 2017
Fixed example codes (semantics)
1 parent 0c2b9c6 commit 4f97a53

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+403
-341
lines changed
 

‎src/array.cr

+14-14
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# `new` method and a `<<` method. `Set` is one such type:
3232
#
3333
# ```
34-
# set = Set{1, 2, 3} # => [1, 2, 3]
34+
# set = Set{1, 2, 3} # => Set{1, 2, 3}
3535
# set.class # => Set(Int32)
3636
# ```
3737
#
@@ -313,7 +313,7 @@ class Array(T)
313313
# ary[0] = 5
314314
# p ary # => [5,2,3]
315315
#
316-
# ary[3] = 5 # => IndexError
316+
# ary[3] = 5 # raises IndexError
317317
# ```
318318
@[AlwaysInline]
319319
def []=(index : Int, value : T)
@@ -449,7 +449,7 @@ class Array(T)
449449
# a = ["a", "b", "c", "d", "e"]
450450
# a[1..3] # => ["b", "c", "d"]
451451
# a[4..7] # => ["e"]
452-
# a[6..10] # => Index Error
452+
# a[6..10] # raise IndexError
453453
# a[5..10] # => []
454454
# a[-2...-1] # => ["d"]
455455
# ```
@@ -469,7 +469,7 @@ class Array(T)
469469
# ```
470470
# a = ["a", "b", "c", "d", "e"]
471471
# a[-3, 3] # => ["c", "d", "e"]
472-
# a[6, 1] # => Index Error
472+
# a[6, 1] # raise IndexError
473473
# a[1, 2] # => ["b", "c"]
474474
# a[5, 1] # => []
475475
# ```
@@ -618,7 +618,7 @@ class Array(T)
618618
# a = ["ant", "bat", "cat", "dog"]
619619
# a.delete_at(2) # => "cat"
620620
# a # => ["ant", "bat", "dog"]
621-
# a.delete_at(99) # => IndexError
621+
# a.delete_at(99) # raises IndexError
622622
# ```
623623
def delete_at(index : Int)
624624
index = check_index_out_of_bounds index
@@ -638,7 +638,7 @@ class Array(T)
638638
# a = ["ant", "bat", "cat", "dog"]
639639
# a.delete_at(1..2) # => ["bat", "cat"]
640640
# a # => ["ant", "dog"]
641-
# a.delete_at(99..100) # => IndexError
641+
# a.delete_at(99..100) # raises IndexError
642642
# ```
643643
def delete_at(range : Range(Int, Int))
644644
from, size = range_to_index_and_count(range)
@@ -654,7 +654,7 @@ class Array(T)
654654
# a = ["ant", "bat", "cat", "dog"]
655655
# a.delete_at(1, 2) # => ["bat", "cat"]
656656
# a # => ["ant", "dog"]
657-
# a.delete_at(99, 1) # => IndexError
657+
# a.delete_at(99, 1) # raises IndexError
658658
# ```
659659
def delete_at(index : Int, count : Int)
660660
val = self[index, count]
@@ -1014,7 +1014,7 @@ class Array(T)
10141014
# iter.next # => [2, 3, 1]
10151015
# iter.next # => [3, 1, 2]
10161016
# iter.next # => [3, 2, 1]
1017-
# iter.next # => Iterator::Stop
1017+
# iter.next # => #<Iterator::Stop>
10181018
# ```
10191019
#
10201020
# By default, a new array is created and returned for each permutation.
@@ -1109,8 +1109,8 @@ class Array(T)
11091109
# ```
11101110
# s = [1, 2, 3] # => [1, 2, 3]
11111111
# t = [4, 5, 6, [7, 8]] # => [4, 5, 6, [7, 8]]
1112-
# u = [9, [10, 11].each] # => [9, Indexable#ItemIterator]
1113-
# a = [s, t, u, 12, 13] # => [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10]
1112+
# u = [9, [10, 11].each] # => [9, #<Indexable::ItemIterator>]
1113+
# a = [s, t, u, 12, 13] # => [[1, 2, 3], [4, 5, 6, [7, 8]], 9, #<Indexable::ItemIterator>, 12, 13]
11141114
# a.flatten # => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
11151115
# ```
11161116
def flatten
@@ -1325,7 +1325,7 @@ class Array(T)
13251325
# ```
13261326
# a = ["a", "b"]
13271327
# a.push("c") # => ["a", "b", "c"]
1328-
# a.push(1) # => Errors, because the array only accepts String.
1328+
# a.push(1) # Errors, because the array only accepts String.
13291329
#
13301330
# a = ["a", "b"] of (Int32 | String)
13311331
# a.push("c") # => ["a", "b", "c"]
@@ -1714,12 +1714,12 @@ class Array(T)
17141714
#
17151715
# ```
17161716
# a = ["a", "b"]
1717-
# a.unshift("c") # => ["c", a", "b"]
1718-
# a.unshift(1) # => Errors, because the array only accepts String.
1717+
# a.unshift("c") # => ["c", "a", "b"]
1718+
# a.unshift(1) # Errors, because the array only accepts String.
17191719
#
17201720
# a = ["a", "b"] of (Int32 | String)
17211721
# a.unshift("c") # => ["c", "a", "b"]
1722-
# a.unshift(1) # => [1, "a", "b", "c"]
1722+
# a.unshift(1) # => [1, "c", "a", "b"]
17231723
# ```
17241724
def unshift(obj : T)
17251725
insert 0, obj

‎src/atomic.cr

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ struct Atomic(T)
104104
#
105105
# ```
106106
# atomic = Atomic.new(5)
107-
# atomic.or(3) # => 5
108-
# atomic.get # => 6
107+
# atomic.xor(3) # => 5
108+
# atomic.get # => 6
109109
# ```
110110
def xor(value : T)
111111
Ops.atomicrmw(:xor, pointerof(@value), value, :sequentially_consistent, false)
@@ -153,8 +153,8 @@ struct Atomic(T)
153153
#
154154
# ```
155155
# atomic = Atomic.new(5)
156-
# atomic.set(10) # => 5
157-
# atomic.get # => 10
156+
# atomic.swap(10) # => 5
157+
# atomic.get # => 10
158158
# ```
159159
def swap(value : T)
160160
Ops.atomicrmw(:xchg, pointerof(@value), value, :sequentially_consistent, false)

0 commit comments

Comments
 (0)
Please sign in to comment.