Skip to content

Instantly share code, notes, and snippets.

@mertyildiran
Created March 17, 2014 13:05
Show Gist options
  • Save mertyildiran/9598826 to your computer and use it in GitHub Desktop.
Save mertyildiran/9598826 to your computer and use it in GitHub Desktop.
Nesne Yonelimli Programlama Odev 1
#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
#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
#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
#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