Created
June 8, 2017 04:06
-
-
Save muhammadyana/5e567c50f5392bf1bb21bda3fbf5b71a 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
#thursday-08-2017 | |
#@41studio | |
#Muhammad Yana Mulyana | |
#inheritance in ruby | |
class Parent | |
def say_hello | |
puts "Hello From #{self}" | |
end | |
end | |
class Child < Parent | |
end | |
parent = Parent.new | |
# parent.say_hello | |
# | |
child = Child.new | |
child.say_hello | |
p Child.superclass # parent | |
p Child.superclass.inspect | |
p Parent.superclass # become an object | |
p Object.superclass | |
class Person | |
def initialize(name) | |
@name = name | |
end | |
def to_s #convert object into string | |
"My name is #{@name}" | |
end | |
end | |
a = Person.new("Yana") | |
puts a.to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment