Created
March 16, 2014 22:52
-
-
Save Rahajustone/9591041 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
#!/usr/bin/ruby | |
# encoding: utf-8 | |
class Merhaba | |
attr_reader:x ,:y | |
def initialize(x,y) | |
@x,@y=x,y | |
end | |
def to_s | |
"(#{@x},#{@y})" | |
end | |
#XXX Sinif metodu tasarlandim,ve burda self yerinde Merhaba koyabliriz.. | |
def self.ben(this) | |
self.new this.x, this.y | |
end | |
end | |
def main | |
p=Merhaba.new("Merahaba ben bir sinif metodmuyum","ve rahmatullo kholov tarafinda tasarlandim" ) | |
puts p | |
puts Merhaba.ben Merhaba.new("ben bir sinif metodum","ve sinif metoduyum olarak ana fonksiyon içinde boyle cağiririm") | |
end | |
main if __FILE__ == $PROGRAM_NAME | |
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
#!/usr/bin/ruby | |
# encoding: utf-8 | |
class Animal | |
#XXX Bir fonk tasarlandik | |
def yaz | |
"hayvanlardan merhaba" | |
end | |
end | |
#XXX Miras Alma | |
class Human < Animal | |
def yaz1 | |
"insanlar haklidir" | |
end | |
end | |
def main | |
#XXX Joe değişkeni nesne metodu | |
joe=Human.new() | |
puts joe.yaz(),joe.yaz1() | |
end | |
main if __FILE__ == $PROGRAM_NAME | |
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
#!/usr/bin/ruby | |
# encoding: utf-8 | |
class Animal | |
#XXX Bir fonk tasarlandik | |
def yaz | |
"hayvanlardan merhaba" | |
end | |
end | |
#XXX Miras Alma | |
class Human < Animal | |
def yaz1 | |
"insanlar haklidir" | |
end | |
end | |
#XXX BU siniflar Animal siniflardan miras aliyor.... | |
class Fish < Animal | |
def swim | |
"Balaklar yuzer" | |
end | |
def fly | |
"Baliklar uçamaz" | |
end | |
end | |
#XXX Zincereleme kural miras almada kulandik mesala fish yerine Animal yazabilirdik.. | |
class Bird < Fish | |
def swim | |
"Kuşlar yuzemez" | |
end | |
def fly | |
"Kuşlar uçar" | |
end | |
end | |
def main | |
#XXX Bir sinifin sinif erişim... | |
balik=Fish.new() | |
kus=Bird.new() | |
puts balik.fly(),kus.swim(),kus.yaz(),balik.yaz() | |
end | |
main if __FILE__ == $PROGRAM_NAME | |
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
#!/usr/bin/ruby | |
# encoding: utf-8 | |
class Personal | |
attr_reader:name | |
def self.name=(degisken) | |
@name = degisken | |
end | |
end | |
class Doktor <Personal | |
def self.name=(degisken) | |
@name=degisken | |
puts "Dr." + @name | |
end | |
end | |
def main | |
degisken = gets.chomp #XXX kulancidan isim al. Dişarda değer alir. | |
Doktor.name=(degisken) | |
end | |
main if __FILE__ == $PROGRAM_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment