examples/person_example.rb in simplecheck-1.0 vs examples/person_example.rb in simplecheck-2.0
- old
+ new
@@ -3,53 +3,47 @@
class Person
include Simplecheck
include Comparable
- attr_accessor( :name, :surname, :date_of_birth )
+ attr_accessor :name, :surname, :date_of_birth
- def initialize( name, surname, date_of_birth )
- check( name, surname, String )
- check( date_of_birth, Date )
+ def initialize(name, surname, date_of_birth)
+ check name, surname, String
+ check date_of_birth, Date
@name = name
@surname = surname
@date_of_birth = date_of_birth
end
- def <=>( person )
- check( person, Person )
- check( person.date_of_birth )
+ def <=>(other)
+ check other, Person
+ check other.date_of_birth
- self.date_of_birth <=> person.date_of_birth
+ date_of_birth <=> other.date_of_birth
end
end
def try
- begin
- yield
- rescue Simplecheck::CheckFailed => exception
- puts "Check Failed: #{ exception.message }"
- rescue => exception
- puts "EXCEPTION: #{ exception.message }"
- end
+ yield
+rescue Simplecheck::CheckFailed => exception
+ puts "Simplecheck::CheckFailed: #{ exception.message }"
end
# date_of_birth is not a Date
-try{ Person.new( 'Bob', 'Roberts', '1980-01-01' )}
+try { Person.new('Bob', 'Roberts', '1980-01-01') }
-bob = Person.new( 'Bob', 'Roberts', Date.civil( 1970, 1, 1 ))
-joe = Person.new( 'Joe', 'Josephs', Date.civil( 1980, 1, 1 ))
+bob = Person.new('Bob', 'Roberts', Date.civil(1970, 1, 1))
+joe = Person.new('Joe', 'Josephs', Date.civil(1980, 1, 1))
# 1 is not a Person
-try{ bob > 1 }
+try { bob > 1 }
-if joe > bob
- puts "Joe > Bob"
-end
+puts 'Joe > Bob' if joe > bob
bob.date_of_birth = nil
# date_of_birth is not present
-try{ joe > bob }
+try { joe > bob }
-puts "Finished"
+puts 'Finished'