Last active
July 12, 2016 09:45
-
-
Save joecorcoran/8a7c082b74c9e2f1da6429eb5714fc05 to your computer and use it in GitHub Desktop.
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
# Code challenge! | |
# | |
# 1. Save the contents of this gist in a | |
# file named classes.rb | |
# | |
# 2. Define the initialize method for class B | |
# so that, when you run `ruby classes.rb`, | |
# the output in the terminal is `true` | |
# | |
# (Don't define any other methods or | |
# change existing ones!) | |
# | |
# Some terms to search for when attempting | |
# this challenge: class method, instance method, | |
# inheritance, super. | |
class A | |
def initialize(message) | |
@message = message | |
end | |
end | |
class B < A | |
def self.create(message) | |
new(message + '!') | |
end | |
def message | |
@message | |
end | |
end | |
b = B.create('hello') | |
puts b.message == 'HELLO!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment