Skip to content

Instantly share code, notes, and snippets.

@domgetter
Created June 9, 2013 09:05
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 domgetter/5742890 to your computer and use it in GitHub Desktop.
Save domgetter/5742890 to your computer and use it in GitHub Desktop.
#in child_class_test.rb
word = Word.new
#EOF child_class_test.rb
# in lib/word.rb
require_relative 'noun'
class Word
attr_reader :word, :part_of_speech, :definition, :etymology, :pronunciation
def initialize
@word = Noun.new
end
def to_s
@word.to_s
end
end
# EOF word.rb
# in lib/noun.rb
class Noun < Word
def initialize
@word = "cat"
@part_of_speech = :noun
end
end
# EOF noun.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment