Skip to content

Instantly share code, notes, and snippets.

@ryanckulp
Created June 8, 2020 10:54
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 ryanckulp/a0e26e0d2a3a47d0c8bdc1325a2843ae to your computer and use it in GitHub Desktop.
Save ryanckulp/a0e26e0d2a3a47d0c8bdc1325a2843ae to your computer and use it in GitHub Desktop.
OOP - Multiple File Execution
# put this in a file, dog.rb
class Dog
attr_accessor :name
def initialize(name)
@name = name
end
def bark!
puts "I'm a #{self.class} and my name is #{name}!"
end
end
# put this in another file, stored in the same directory as the "dog.rb" file above
require_relative 'dog'
class Poodle < Dog
end
p = Poodle.new('Sally')
p.bark!
# execute via "cd-ing" into the directory with poodle.rb, then:
# ruby poodle.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment