Created
March 17, 2014 13:05
-
-
Save mertyildiran/9598826 to your computer and use it in GitHub Desktop.
Nesne Yonelimli Programlama Odev 1
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
#encoding: UTF-8 | |
class Merhaba | |
def self.class_method | |
puts "Merhaba, ben bir sınıf metoduyum!" | |
end | |
def instance_method | |
puts "Merhaba, ben bir nesne metoduyum!" | |
end | |
end | |
Merhaba.class_method | |
#Merhaba.instance_method --> hata verir | |
#Merhaba.new.class_method --> hata verir | |
Merhaba.new.instance_method |
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
#encoding: UTF-8 | |
class Animal | |
def hello | |
puts "Hayvanlardan merhaba!" | |
end | |
end | |
class Human < Animal | |
def intellect | |
puts "İnsanlar akıllıdır!" | |
end | |
end | |
joe = Human.new | |
joe.hello | |
joe.intellect |
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
#encoding: UTF-8 | |
class Animal | |
def hello | |
puts "Hayvanlardan merhaba!" | |
end | |
end | |
class Human < Animal | |
def intellect | |
puts "İnsanlar akıllıdır!" | |
end | |
end | |
class Fish < Animal | |
def swim | |
puts "Yüzüyorum!" | |
end | |
end | |
class Bird < Animal | |
def fly | |
puts "Uçuyorum!" | |
end | |
end | |
fish1 = Fish.new | |
bird1 = Bird.new | |
fish1.swim | |
bird1.fly |
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
#encoding: UTF-8 | |
class Person | |
def initialize(name) | |
@name = name | |
end | |
def getter_name | |
puts @name | |
end | |
end | |
class Doctor < Person | |
def getter_name | |
print "Dr. " | |
super | |
end | |
end | |
doctor1 = Doctor.new("Mehmet") | |
doctor1.getter_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment