Recent Changes - Search:

edit SideBar


Firefox 2
Get Thunderbird!

Hashes

Ruby.Hashes History

Hide minor edits - Show changes to markup

May 30, 2008, at 06:40 PM by 78.188.55.33
Added lines 112-117:
  1. sadece "sort" kullanarak yaptığımız sıralama sonunda
  2. d�nd�r�len değer hash yerine bir array'dir.

h = {:ad => "Oz", :soyad => "Ko", :adres => "Ist"} h.sort {|a, b| a.to_s <=> b.to_s}

  1. => :ad, "Oz"], [:adres, "Istanbul"], [:soyad, "Ko"?
May 30, 2008, at 06:16 PM by 78.188.55.33
Changed lines 105-106 from:

=]

to:
Changed lines 109-110 from:
	puts h[key]

end

to:

puts h[key] end

=]

May 30, 2008, at 06:16 PM by 78.188.55.33
Changed lines 105-111 from:

=]

to:

=]

  1. hash'in key'lerine g�re sıralama yapmak.

h = {"1" => "bir", "7" => "yedi", "2" => "iki"} h.keys.sort {|a,b| a.to_i <=> b.to_i}.each do |key|

	puts h[key]

end

November 29, 2006, at 11:00 PM by 85.105.66.26
Added lines 1-105:

(:code:) #!/usr/bin/ruby # # Hashes # # hash olu&#351;turulmas&#305; h = { "a" => 1, "b" => 2 } h2 = Hash.new #yeni hash olu&#351;turulur h2[:ad] = "Oz" #hash'e de&#287;er atan&#305;r h2[:soyad] = "Ko" #hash'e de&#287;er atan&#305;r #hash'in elemanlar&#305;na ula&#351;&#305;lmas&#305; h["a"] h["b"] #hash'e yeni eleman eklenmesi h["c"] = 3; #Like an array, a hash contains references to objects, not copies of them. #Modifications to the original objects will affect all references to them: motto = "Don't thread on me" flag = { :motto => motto, :picture => "picture.png" } motto.upcase! flag[:motto] #Hash'lerde key olarak symbol kullan&#305;lmas&#305; �nerilir. bu i&#351; 2 yolla yap&#305;labilir. #Using symbols instead of strings saves memory and time. #It saves memory because there's only one symbol instance, instead of many string instances. #If you have many hashes that contain the same keys, the memory savings adds up. #Using symbols as hash keys is faster because the hash value of a symbol is simply its object ID. #If you use strings in a hash, Ruby must calculate the hash value of a string each time it's used as a hash key. h = Hash.new h[:name] = "Oz" # veya h['name'.intern] = "Oz"; # �ntan&#305;ml&#305; de&#287;eriyle birlikte hash olu&#351;uturulmas&#305; h = Hash.new("default value") h[1] #default value h['heyyo'] #default value h[:x] #default value # &#304;ki hash'in birle&#351;tirilmesi h1 = { "a"=> 1, "b"=>2 } h2 = { "c"=> 3, "d"=>4 } h1.merge!(h2) # Bir hash'in de&#287;erinin ba&#351;ka bir hash ile de&#287;i&#351;tirilmesi h1 = { "a"=> 1, "b"=>2 } h2 = { "a"=> 3, "b"=>4 } h1.replace(h2) #Hash'ten eleman silinmesi h = { 1 => "aaa" } h.delete(1) #hash'in key'lerine ula&#351;&#305;lmas&#305; h = { "a"=> 1, "b"=>2 } h.keys #hash'in value'lerine ula&#351;&#305;lmas&#305; h = { "a"=> 1, "b"=>2 } h.values #hash'in eleman say&#305;s&#305;n&#305;n bulunmas&#305; h = { "a"=> 1, "b"=>2 } h.keys.size #Hash'in t�m elemanlar&#305;n&#305; silmek i�in h = { "a"=> 1, "b"=>2 } h.clear #Hash'in key,value �iftleri aras&#305;nda gezinme h = { "a"=> 1, "b"=>2, "d" => 4, "c" => 3} h.each_pair { |key, value| puts "key: #{key} value: #{value}" } #Hash'in keyleri aras&#305;nda gezinme h = { "a"=> 1, "b"=>2, "d" => 4, "c" => 3} h.each_key { |key| puts key } #Hash'in value'leri aras&#305;nda gezinme h = { "a"=> 1, "b"=>2, "d" => 4, "c" => 3} h.each_value { |val| puts val } #Hash'in diziye d�n�&#351;t�r�lmesi h = { "a"=> 1, "b"=>2, "d" => 4, "c" => 3} h.to_a #Hash'in keylere g�re s&#305;ralanmas&#305; h = { "a"=> 1, "b"=>2, "d" => 4, "c" => 3} h.keys.sort.each do |x| puts x end #&#304;�i�e hash'lerdeki i�teki hash'in de&#287;erlerine ula&#351;&#305;lmas&#305; h = Hash.new h[:phone] = { :work => "5555555", :gsm => "999999999"} h[:phone].each_pair do |k,v| puts "#{k} #{v}" end #hash'in keyleri aras&#305;nda arama yapma h = { "a"=> 1, "b"=>2, "d" => 4, "c" => 3} h.keys.grep /[^ab]/

Edit - History - Print - Recent Changes - Search
Page last modified on May 30, 2008, at 06:40 PM