Skip to content

Instantly share code, notes, and snippets.

@benjaminxscott
Created October 8, 2015 01:13
Show Gist options
  • Save benjaminxscott/e9d08a0c98a585cb94e7 to your computer and use it in GitHub Desktop.
Save benjaminxscott/e9d08a0c98a585cb94e7 to your computer and use it in GitHub Desktop.
an example ruby class
#!/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