Skip to content

Instantly share code, notes, and snippets.

@muhammadyana
Created June 8, 2017 04:06
Show Gist options
  • Save muhammadyana/5e567c50f5392bf1bb21bda3fbf5b71a to your computer and use it in GitHub Desktop.
Save muhammadyana/5e567c50f5392bf1bb21bda3fbf5b71a to your computer and use it in GitHub Desktop.
#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