Last active
August 29, 2015 14:01
-
-
Save uberbrady/dd12f2f2d8e9fe5a0e6d to your computer and use it in GitHub Desktop.
First the "wrong" way then the "right" way, and how that can get out of hand.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
def age | |
Date.now-birthyear | |
end | |
end | |
test "That a person has an age" do | |
p=Person.new 1974 | |
travel_to 2014 | |
assert(p.age==40) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
def age(now=Date.now) | |
now-birthyear | |
end | |
end | |
test "that a person has an age" do | |
p=Person.new 1974 | |
assert(p.age(2014)==40) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
def age(now=Date.now) | |
now-birthyear | |
end | |
def can_drink_yet?(now=Date.now) | |
age(now)>21 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment