Skip to content

Instantly share code, notes, and snippets.

@thex00
Created August 7, 2010 23:24
Show Gist options
  • Save thex00/513313 to your computer and use it in GitHub Desktop.
Save thex00/513313 to your computer and use it in GitHub Desktop.
cross-over
# 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