Skip to content

Commit 88fd1d8

Browse files
committed
* Update all references to Fixnum to Integer
Deprecated in ruby 2.4
1 parent 7455aa9 commit 88fd1d8

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

.rubocop.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Style/Documentation:
6464
Layout/LineLength:
6565
Enabled: false
6666

67-
# triggered by Contract ({ :name => String, :age => Fixnum }) => nil
67+
# triggered by Contract ({ :name => String, :age => Integer }) => nil
6868
Lint/ParenthesesAsGroupedExpression:
6969
Enabled: false
7070

TUTORIAL.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ contracts.ruby comes with a lot of built-in contracts, including the following:
8080

8181
* Logical combinations
8282
* [`Maybe`](http://www.rubydoc.info/gems/contracts/Contracts/Builtin/Maybe) – specifies that a value _may be_ nil, e.g. `Maybe[String]` (equivalent to `Or[String,nil]`)
83-
* [`Or`](http://www.rubydoc.info/gems/contracts/Contracts/Builtin/Or) – passes if any of the given contracts pass, e.g. `Or[Fixnum, Float]`
84-
* [`Xor`](http://www.rubydoc.info/gems/contracts/Contracts/Builtin/Xor) – passes if exactly one of the given contracts pass, e.g. `Xor[Fixnum, Float]`
83+
* [`Or`](http://www.rubydoc.info/gems/contracts/Contracts/Builtin/Or) – passes if any of the given contracts pass, e.g. `Or[Integer, Float]`
84+
* [`Xor`](http://www.rubydoc.info/gems/contracts/Contracts/Builtin/Xor) – passes if exactly one of the given contracts pass, e.g. `Xor[Integer, Float]`
8585
* [`And`](http://www.rubydoc.info/gems/contracts/Contracts/Builtin/And) – passes if all contracts pass, e.g. `And[Nat, -> (n) { n.even? }]`
8686
* [`Not`](http://www.rubydoc.info/gems/contracts/Contracts/Builtin/Not) – passes if all contracts fail for the given argument, e.g. `Not[nil]`
8787

8888
* Collections
8989
* [`ArrayOf`](http://www.rubydoc.info/gems/contracts/Contracts/Builtin/ArrayOf) – checks that the argument is an array, and all elements pass the given contract, e.g. `ArrayOf[Num]`
9090
* [`SetOf`](http://www.rubydoc.info/gems/contracts/Contracts/Builtin/SetOf) – checks that the argument is a set, and all elements pass the given contract, e.g. `SetOf[Num]`
9191
* [`HashOf`](http://www.rubydoc.info/gems/contracts/Contracts/Builtin/HashOf) – checks that the argument is a hash, and all keys and values pass the given contract, e.g. `HashOf[Symbol => String]` or `HashOf[Symbol,String]`
92-
* [`StrictHash`](http://www.rubydoc.info/gems/contracts/Contracts/Builtin/StrictHash) – checks that the argument is a hash, and every key passed is present in the given contract, e.g. `StrictHash[{ :description => String, :number => Fixnum }]`
92+
* [`StrictHash`](http://www.rubydoc.info/gems/contracts/Contracts/Builtin/StrictHash) – checks that the argument is a hash, and every key passed is present in the given contract, e.g. `StrictHash[{ :description => String, :number => Integer }]`
9393
* [`RangeOf`](http://www.rubydoc.info/gems/contracts/Contracts/Builtin/RangeOf) – checks that the argument is a range whose elements (#first and #last) pass the given contract, e.g. `RangeOf[Date]`
9494
* [`Enum`](http://www.rubydoc.info/gems/contracts/Contracts/Builtin/Enum) – checks that the argument is part of a given collection of objects, e.g. `Enum[:a, :b, :c]`
9595

@@ -152,7 +152,7 @@ end
152152

153153
You always need to specify a contract for the return value. In this example, `hello` doesn't return anything, so the contract is `nil`. Now you know that you can use a constant like `nil` as the end of a contract. Valid values for a contract are:
154154

155-
- the name of a class (like `String` or `Fixnum`)
155+
- the name of a class (like `String` or `Integer`)
156156
- a constant (like `nil` or `1`)
157157
- a `Proc` that takes a value and returns true or false to indicate whether the contract passed or not
158158
- a class that responds to the `valid?` class method (more on this later)
@@ -161,32 +161,32 @@ You always need to specify a contract for the return value. In this example, `he
161161
### A Double Function
162162

163163
```ruby
164-
Contract C::Or[Fixnum, Float] => C::Or[Fixnum, Float]
164+
Contract C::Or[Integer, Float] => C::Or[Integer, Float]
165165
def double(x)
166166
2 * x
167167
end
168168
```
169169

170170
Sometimes you want to be able to choose between a few contracts. `Or` takes a variable number of contracts and checks the argument against all of them. If it passes for any of the contracts, then the `Or` contract passes.
171-
This introduces some new syntax. One of the valid values for a contract is an instance of a class that responds to the `valid?` method. This is what `Or[Fixnum, Float]` is. The longer way to write it would have been:
171+
This introduces some new syntax. One of the valid values for a contract is an instance of a class that responds to the `valid?` method. This is what `Or[Integer, Float]` is. The longer way to write it would have been:
172172

173173
```ruby
174-
Contract C::Or.new(Fixnum, Float) => C::Or.new(Fixnum, Float)
174+
Contract C::Or.new(Integer, Float) => C::Or.new(Integer, Float)
175175
```
176176

177177
All the built-in contracts have overridden the square brackets (`[]`) to give the same functionality. So you could write
178178

179179
```ruby
180-
Contract C::Or[Fixnum, Float] => C::Or[Fixnum, Float]
180+
Contract C::Or[Integer, Float] => C::Or[Integer, Float]
181181
```
182182

183183
or
184184

185185
```ruby
186-
Contract C::Or.new(Fixnum, Float) => C::Or.new(Fixnum, Float)
186+
Contract C::Or.new(Integer, Float) => C::Or.new(Integer, Float)
187187
```
188188

189-
whichever you prefer. They both mean the same thing here: make a new instance of `Or` with `Fixnum` and `Float`. Use that instance to validate the argument.
189+
whichever you prefer. They both mean the same thing here: make a new instance of `Or` with `Integer` and `Float`. Use that instance to validate the argument.
190190

191191
### A Product Function
192192

@@ -455,7 +455,7 @@ Now you can use `Person` wherever you would have used `Or[Hash, nil]`. Your code
455455

456456
Contracts are very easy to define. To re-iterate, there are 5 kinds of contracts:
457457

458-
- the name of a class (like `String` or `Fixnum`)
458+
- the name of a class (like `String` or `Integer`)
459459
- a constant (like `nil` or `1`)
460460
- a `Proc` that takes a value and returns true or false to indicate whether the contract passed or not
461461
- a class that responds to the `valid?` class method (more on this later)
@@ -511,7 +511,7 @@ The `Or` contract takes a sequence of contracts, and passes if any of them pass.
511511
This class inherits from `CallableClass`, which allows us to use `[]` when using the class:
512512

513513
```ruby
514-
Contract C::Or[Fixnum, Float] => C::Num
514+
Contract C::Or[Integer, Float] => C::Num
515515
def double(x)
516516
2 * x
517517
end
@@ -520,7 +520,7 @@ end
520520
Without `CallableClass`, we would have to use `.new` instead:
521521

522522
```ruby
523-
Contract C::Or.new(Fixnum, Float) => C::Num
523+
Contract C::Or.new(Integer, Float) => C::Num
524524
def double(x)
525525
# etc
526526
```
@@ -723,7 +723,7 @@ class MyBirthday < Struct.new(:day, :month)
723723
invariant(:day) { 1 <= day && day <= 31 }
724724
invariant(:month) { 1 <= month && month <= 12 }
725725

726-
Contract C::None => Fixnum
726+
Contract C::None => Integer
727727
def silly_next_day!
728728
self.day += 1
729729
end

lib/contracts/builtin_contracts.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def self.[](*vals)
9595

9696
# Takes a variable number of contracts.
9797
# The contract passes if any of the contracts pass.
98-
# Example: <tt>Or[Fixnum, Float]</tt>
98+
# Example: <tt>Or[Integer, Float]</tt>
9999
class Or < CallableClass
100100
def initialize(*vals)
101101
super()
@@ -120,7 +120,7 @@ def to_s
120120

121121
# Takes a variable number of contracts.
122122
# The contract passes if exactly one of those contracts pass.
123-
# Example: <tt>Xor[Fixnum, Float]</tt>
123+
# Example: <tt>Xor[Integer, Float]</tt>
124124
class Xor < CallableClass
125125
def initialize(*vals)
126126
super()
@@ -146,7 +146,7 @@ def to_s
146146

147147
# Takes a variable number of contracts.
148148
# The contract passes if all contracts pass.
149-
# Example: <tt>And[Fixnum, Float]</tt>
149+
# Example: <tt>And[Integer, Float]</tt>
150150
class And < CallableClass
151151
def initialize(*vals)
152152
super()

spec/builtin_contracts_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def passes(&some)
3030
end
3131

3232
describe "Num:" do
33-
it "should pass for Fixnums" do
33+
it "should pass for Integers" do
3434
passes { @o.double(2) }
3535
end
3636

spec/fixtures/fixtures.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ def sum_three(vals)
100100
end
101101
end
102102

103-
Contract ({ :name => String, :age => Fixnum }) => nil
103+
Contract ({ :name => String, :age => Integer }) => nil
104104
def person(data)
105105
end
106106

107-
Contract C::StrictHash[{ :name => String, :age => Fixnum }] => nil
107+
Contract C::StrictHash[{ :name => String, :age => Integer }] => nil
108108
def strict_person(data)
109109
end
110110

@@ -119,7 +119,7 @@ def hash_complex_contracts(data)
119119
def nested_hash_complex_contracts(data)
120120
end
121121

122-
Contract C::KeywordArgs[:name => String, :age => Fixnum] => nil
122+
Contract C::KeywordArgs[:name => String, :age => Integer] => nil
123123
def person_keywordargs(name: "name", age: 10)
124124
end
125125

@@ -529,30 +529,30 @@ def initialize(day, month)
529529
@month = month
530530
end
531531

532-
Contract C::None => Fixnum
532+
Contract C::None => Integer
533533
def silly_next_day!
534534
self.day += 1
535535
end
536536

537-
Contract C::None => Fixnum
537+
Contract C::None => Integer
538538
def silly_next_month!
539539
self.month += 1
540540
end
541541

542-
Contract C::None => Fixnum
542+
Contract C::None => Integer
543543
def clever_next_day!
544544
return clever_next_month! if day == 31
545545
self.day += 1
546546
end
547547

548-
Contract C::None => Fixnum
548+
Contract C::None => Integer
549549
def clever_next_month!
550550
return next_year! if month == 12
551551
self.month += 1
552552
self.day = 1
553553
end
554554

555-
Contract C::None => Fixnum
555+
Contract C::None => Integer
556556
def next_year!
557557
self.month = 1
558558
self.day = 1
@@ -610,7 +610,7 @@ def on_response(status, body)
610610
body + "!"
611611
end
612612

613-
Contract Fixnum, String => String
613+
Contract Integer, String => String
614614
def on_response(status, body)
615615
"error #{status}: #{body}"
616616
end

0 commit comments

Comments
 (0)