Skip to content

Instantly share code, notes, and snippets.

@uberbrady
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uberbrady/dd12f2f2d8e9fe5a0e6d to your computer and use it in GitHub Desktop.
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.
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
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
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