An example of that code is below.
class Human
@name
@age
@wanryoku
def walk
end
def eat
end
def age= num
if num < 0
puts
@age = 0
return
end
@age = num
end
end
class SuperMan < Human
def me_kara_beam
end
end
human = Human.new
human.walk #ok
human.me_kara_beam #error
spMan = SuperMan.new
spMan.walk #ok
spMan.me_kara_beam #ok
This is because humans can walk, but they can't get a beam out of their eyes. Superman (spMan) can walk and emit a beam from his eyes It is a process called.
I think that programming that seems difficult at first glance may be interesting when viewed in this way.
I've documented my daily learning, so please take a look at it in your spare time. https://www.notion.so/Ruby-Ruby-on-Rails-84f5c88189474fa4aae5e00cba856226
Recommended Posts