[ create a new paste ] login | about

Link: http://codepad.org/otg6uCQp    [ raw code | output | fork ]

Ruby, pasted on May 16:
#!/usr/bin/env ruby

exampleFruitQuantities = {
  :apples     => 4,
  :pineapples => 2,
  :grapes     => 30
} 

def generateHash(hash)
  # Here I declare a hash and define its elements.
  generatedHash = Hash.new
  hash.each do |fruit|
    generatedHash[fruit[0]] = fruit[1]
  end

  # Now I have to return it.
  return generatedHash
end

def justDefineIt
  # If I could build a hash this way, I wouldn't have to declare or return anything.
  'test'
end

puts generateHash(exampleFruitQuantities).inspect
puts justDefineIt.inspect


Output:
1
2
{:grapes=>30, :apples=>4, :pineapples=>2}
"test"


Create a new paste based on this one


Comments: