Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save muratatak77/01d012e220d71eb7ba17 to your computer and use it in GitHub Desktop.
Save muratatak77/01d012e220d71eb7ba17 to your computer and use it in GitHub Desktop.
Assgmnt - 1 (String Interpolation , rvm - patch , class )
1. RVM'i kullanarak, Ruby'nin 1.9.3-p452 versiyonunu kurunuz.
*******************************************************************************************************************
452 patchine yok dedi. 1.9.3 dedik 55 uzantılı patchi kurdu.
muratatak@muratatak ~/ror/blog $ rvm install 1.9.3-p452
Searching for binary rubies, this might take some time.
No binary rubies available for: mint/15/x86_64/ruby-1.9.3-p452.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for mint.
Requirements installation successful.
Installing Ruby from source to: /home/muratatak/.rvm/rubies/ruby-1.9.3-p452, this may take a while depending on your cpu(s)...
ruby-1.9.3-p452 - #downloading ruby-1.9.3-p452, this may take a while depending on your connection...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (22) The requested URL returned error: 404 Not Found
The requested url does not exist(22): 'http://cache.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p452.tar.bz2'
Checking fallback: http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p452.tar.bz2
Checking fallback: http://www.mirrorservice.org/sites/ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p452.tar.bz2
No fallback URL could be found, try increasing timeout with:
echo "export rvm_max_time_flag=20" >> ~/.rvmrc
There has been an error fetching the ruby interpreter. Halting the installation.
muratatak@muratatak ~/ror/blog $ rvm list
rvm rubies
ruby-2.0.0-p451 [ x86_64 ]
=* ruby-2.1.1 [ x86_64 ]
# => - current
# =* - current && default
# * - default
muratatak@muratatak ~/ror/blog $ rvm install 1.9.3
Searching for binary rubies, this might take some time.
No binary rubies available for: mint/15/x86_64/ruby-1.9.3-p545.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for mint.
Requirements installation successful.
Installing Ruby from source to: /home/muratatak/.rvm/rubies/ruby-1.9.3-p545, this may take a while depending on your cpu(s)...
ruby-1.9.3-p545 - #downloading ruby-1.9.3-p545, this may take a while depending on your connection...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 9802k 100 9802k 0 0 818k 0 0:00:11 0:00:11 --:--:-- 838k
ruby-1.9.3-p545 - #extracting ruby-1.9.3-p545 to /home/muratatak/.rvm/src/ruby-1.9.3-p545...
ruby-1.9.3-p545 - #applying patch /home/muratatak/.rvm/patches/ruby/GH-488.patch.
ruby-1.9.3-p545 - #configuring.............................................
ruby-1.9.3-p545 - #post-configuration.
ruby-1.9.3-p545 - #compiling..........................................................................................................
ruby-1.9.3-p545 - #installing........................
ruby-1.9.3-p545 - #making binaries executable..
ruby-1.9.3-p545 - #downloading rubygems-2.2.2
ruby-1.9.3-p545 - #extracting rubygems-2.2.2....
ruby-1.9.3-p545 - #removing old rubygems.........
ruby-1.9.3-p545 - #installing rubygems-2.2.2...............
ruby-1.9.3-p545 - #gemset created /home/muratatak/.rvm/gems/ruby-1.9.3-p545@global
ruby-1.9.3-p545 - #importing gemset /home/muratatak/.rvm/gemsets/global.gems.............................................................
ruby-1.9.3-p545 - #generating global wrappers.........
ruby-1.9.3-p545 - #gemset created /home/muratatak/.rvm/gems/ruby-1.9.3-p545
ruby-1.9.3-p545 - #importing gemsetfile /home/muratatak/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-1.9.3-p545 - #generating default wrappers.........
ruby-1.9.3-p545 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-1.9.3-p545 - #complete
WARNING: Please be aware that you just installed a ruby that is no longer maintained (2014-02-23), for a list of maintained rubies visit:
http://bugs.ruby-lang.org/projects/ruby/wiki/ReleaseEngineering
Please consider upgrading to ruby-2.1.1 which will have all of the latest security patches.
Ruby was built without documentation, to build it run: rvm docs generate-ri
muratatak@muratatak ~/ror/blog $
2. Car adlı bir class oluşturunuz. Bu sınıfın brand, model, color, km ve price şeklinde okunabilir ve yazılabilir 5 attribute'ü olsun.
*******************************************************************************************************************
1.9.3-p545 :001 > class Car
1.9.3-p545 :002?> attr_accessor :brand, :model, :color, :km, :price
1.9.3-p545 :003?> end
=> nil
3. Car sınıfında car_presentation adlı bir fonksiyon yazınız. Bu fonksiyon, beraber çağırıldığı Car nesnesi için aşağıdaki gibi bir metin çıktı versin:
Örnek çağrı:
(car bir Car sınıfı örneği olmak üzere)
car.car_presentation
Örnek çıktı:
Merhaba! Şu anda Ford marka, 2012 model, kırmızı renkli ve 1212 km'de bulunan aracımızı görüntülemektesiniz! Bu aracımızın fiyatı 18000 TL! Bu fırsatı kaçırmayın!
*******************************************************************************************************************
class Car
attr_accessor :brand, :model, :color, :km, :price
def initialize(brand,model,color,km,price)
@brand = brand
@model = model
@color = color
@km = km
@price = price
end
def car_presentation
"Merhaba! Şu anda " + @brand + " marka, " + @model + " model " + @color + " renkli ve " + @km + " km'de bulunan aracımızı görüntülemektesiniz! Bu aracımızın fiyatı " + @price + " TL! Bu fırsatı kaçırmayın! "
end
end
2.1.1 :045 > car = Car.new("Ford","2012" , "kırmızı","1212" ,"18000" )
=> #<Car:0x000000026a3888 @brand="Ford", @model="2012", @color="kırmızı", @km=" 1212", @price=" 18000">
2.1.1 :046 > puts car.car_presentation
Merhaba! Şu anda Ford marka, 2012 model kırmızı renkli ve 1212 km'de bulunan aracımızı görüntülemektesiniz! Bu aracımızın fiyatı 18000 TL! Bu fırsatı kaçırmayın!
=> nil
2.1.1 :047 >
4. Car sınıfında installment_calculator adlı bir fonksiyon yazınız. Bu fonksiyonun görevi, beraber çağırıldığı Car nesnesi ile verilen taksit sayısı ile bir taksit tablosu çıkarması.
Örnek çağrı:
(car bir Car sınıfı örneği olmak üzere)
car.installment_calculator(12)
Örnek çıktı:
-------------------------------------------------------------------
Ford - 2012 - kırmızı | (12 eşit taksit)
-------------------------------------------------------------------
1. Taksit Ödemesi => 1500.0 TL
2. Taksit Ödemesi => 1500.0 TL
3. Taksit Ödemesi => 1500.0 TL
4. Taksit Ödemesi => 1500.0 TL
5. Taksit Ödemesi => 1500.0 TL
6. Taksit Ödemesi => 1500.0 TL
7. Taksit Ödemesi => 1500.0 TL
8. Taksit Ödemesi => 1500.0 TL
9. Taksit Ödemesi => 1500.0 TL
10. Taksit Ödemesi => 1500.0 TL
11. Taksit Ödemesi => 1500.0 TL
12. Taksit Ödemesi => 1500.0 TL
*******************************************************************************************************************
class Car
attr_accessor :brand, :model, :color, :km, :price
def initialize(brand,model,color,km,price)
@brand = brand
@model = model
@color = color
@km = km
@price = price
end
def car_presentation
"Merhaba! Şu anda " + @brand + " marka, " + @model + " model " + @color + " renkli ve " + @km + " km'de bulunan aracımızı görüntülemektesiniz! Bu aracımızın fiyatı " + @price + " TL! Bu fırsatı kaçırmayın! "
end
def installment_calculator(installment)
unless @price.to_f % installment.to_i == 0
puts "Esit taksit yapilamaz"
else
payment_amount = @price.to_f / installment
puts "----------------------------------------------"
puts @brand + " - " + @model + " - " + @color + " | " + "( " + installment.to_s + " eşit taksit) "
puts "----------------------------------------------"
installment.times do |i|
puts "#{i}.Taksit Ödemesi =>" + payment_amount.to_s + "TL"
end
end
end
end
Çıktılar >>>>>
=> nil
2.1.1 :052 > class Car
2.1.1 :053?>
2.1.1 :054 > def installment_calculator(installment)
2.1.1 :055?> unless @price.to_f % installment.to_i == 0
2.1.1 :056?> puts "Esit taksit yapilamaz"
2.1.1 :057?> else
2.1.1 :058 > payment_amount = @price.to_f / installment
2.1.1 :059?> puts "----------------------------------------------"
2.1.1 :060?> puts @brand + " - " + @model + " - " + @color + " | " + "( " + installment.to_s + " eşit taksit) "
2.1.1 :061?> puts "----------------------------------------------"
2.1.1 :062?>
2.1.1 :063 > installment.times do |i|
2.1.1 :064 > puts "#{i}.Taksit Ödemesi =>" + payment_amount.to_s + "TL"
2.1.1 :065?> end
2.1.1 :066?> end
2.1.1 :067?> end
2.1.1 :068?> end
=> :installment_calculator
2.1.1 :069 > car.installment_calculator(10)
----------------------------------------------
Ford - 2012 - kırmızı | ( 10 eşit taksit)
----------------------------------------------
0.Taksit Ödemesi =>1800.0TL
1.Taksit Ödemesi =>1800.0TL
2.Taksit Ödemesi =>1800.0TL
3.Taksit Ödemesi =>1800.0TL
4.Taksit Ödemesi =>1800.0TL
5.Taksit Ödemesi =>1800.0TL
6.Taksit Ödemesi =>1800.0TL
7.Taksit Ödemesi =>1800.0TL
8.Taksit Ödemesi =>1800.0TL
9.Taksit Ödemesi =>1800.0TL
=> 10
2.1.1 :070 > car.installment_calculator(13)
Esit taksit yapilamaz
=> nil
2.1.1 :071 > car.installment_calculator(10)
----------------------------------------------
Ford - 2012 - kırmızı | ( 10 eşit taksit)
----------------------------------------------
0.Taksit Ödemesi =>1800.0TL
1.Taksit Ödemesi =>1800.0TL
2.Taksit Ödemesi =>1800.0TL
3.Taksit Ödemesi =>1800.0TL
4.Taksit Ödemesi =>1800.0TL
5.Taksit Ödemesi =>1800.0TL
6.Taksit Ödemesi =>1800.0TL
7.Taksit Ödemesi =>1800.0TL
8.Taksit Ödemesi =>1800.0TL
9.Taksit Ödemesi =>1800.0TL
=> 10
2.1.1 :072 >
Farkettim de 0. taksit yazıyo. Oraya bir +1 koyarız :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment