examples/person.fy in fancy-0.3.2 vs examples/person.fy in fancy-0.3.3
- old
+ new
@@ -1,12 +1,11 @@
# person.fy
# Annotated example of fancy's classes mechanism
class City {
- read_slots: ['city]
- def initialize: name {
- @name = name
+ read_slots: ['name]
+ def initialize: @name {
}
def to_s {
"City: " ++ @name
}
@@ -22,14 +21,11 @@
# method being generated, that calls this method when being called.
# The name of the class factory method is the same as the instance
# method but having initialize: replaced by new:.
# So in this case: Person##new:age:city:
# which calls this instance method internally
- def initialize: name age: age city: city {
- @name = name
- @age = age
- @city = city
+ def initialize: @name age: @age city: @city {
}
def go_to: city {
# The .-operator (dot) manages left associativity and treats
# everything left of it as one expression and everything right of
@@ -48,10 +44,10 @@
@city = city
}
}
def to_s {
- "Person: " ++ @name ++ ", " ++ @age ++ " years old, living in " ++ @city
+ "Person: #{@name}, #{@age} years old, living in #{@city}"
}
}
# usage example:
osna = City new: "Osnabrück"