Created
October 8, 2015 01:13
-
-
Save benjaminxscott/e9d08a0c98a585cb94e7 to your computer and use it in GitHub Desktop.
an example ruby class
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
#!/usr/bin/env ruby | |
class Ghost | |
attr_accessor :haunted | |
def initialize (loc = "house") | |
@locations = loc | |
@haunted = 1 | |
end | |
def bust () | |
if rand.round() == 0 | |
@haunted = 0 | |
puts "this place is clean" | |
else | |
puts "hehehehe" | |
end | |
end | |
def boo () | |
# multiple places | |
if @locations.respond_to?("each") | |
@locations.each do |location| | |
puts "the call is coming from inside the #{location}" | |
end | |
else | |
puts "ITS BEHIND YOU IN THE #{@locations}" | |
end | |
end | |
end # define Ghost | |
# main() | |
if __FILE__ == $0 | |
slimer = Ghost.new() | |
slimer.boo() | |
slimer.bust() | |
mman = Ghost.new('hospital') | |
mman.boo() | |
mman.bust() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment