Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / example_point.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2004-2008 Jean Privat <jean@pryen.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 class Point
18 private
19 var x: Int = 0 # Abscisse
20 var y: Int = 0 # Ordonnée
21
22 # Change la position d'un point
23 fun moveto(x: Int, y: Int)
24 do
25 _x = x
26 _y = y
27 end
28
29 redef fun to_s: String
30 do
31 var s = "({_x}:{_y})"
32 return s
33 end
34
35 redef fun ==(p)
36 do
37 return p isa Point and _x == p.x and _y == p.y
38 end
39
40
41 init at(x: Int, y: Int)
42 do
43 moveto(x, y)
44 end
45
46 end
47
48
49 var p1 = new Point
50 var p2 = new Point.at(5, 8)
51 print(p1) # (0,0)
52 print(p2) # (5,8)
53 print(p1 == p2) # false
54 p1.moveto(5,12)
55 p2.y = 12
56 print(p1 == p2) # true