Created
August 7, 2010 23:24
-
-
Save thex00/513313 to your computer and use it in GitHub Desktop.
cross-over
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
# this Lab is a class with a single method to check if a number is dividable as a | |
# whole number. When it does, it prints out 'foo' and 'bar' and the value of it. | |
class CrazyNum | |
def is_dividable? (value) | |
d_by_three = false | |
d_by_five = false | |
baz = "" | |
div_one = value % 3 | |
div_two = value % 5 | |
if div_one == 0 | |
baz = "foo" | |
d_by_three = true | |
end | |
if div_two == 0 | |
baz = baz + "bar" | |
d_by_five = true | |
end | |
if d_by_three | |
bt = "dividable by 3." | |
else | |
bt = "not dividable by 3." | |
end | |
if d_by_five | |
bf = "dividable by 5." | |
else | |
bf = "not dividable by 5." | |
end | |
puts "#{baz} The value #{value} is #{bt} and is #{bf}" | |
end | |
end | |
a = CrazyNum.new | |
1.upto(100) { |x| a.is_dividable? x } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment