Skip to content

Instantly share code, notes, and snippets.

@joecorcoran
Last active July 12, 2016 09:45
Show Gist options
  • Save joecorcoran/8a7c082b74c9e2f1da6429eb5714fc05 to your computer and use it in GitHub Desktop.
Save joecorcoran/8a7c082b74c9e2f1da6429eb5714fc05 to your computer and use it in GitHub Desktop.
# 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