Rails optimizing app performance
I learned about techniques that Chis Oliver, the author of GoRails screencast series, uses to optimize the performance of GoRails site. The contents below are my personal notes for GoRails - Episode 113.
I learned about techniques that Chis Oliver, the author of GoRails screencast series, uses to optimize the performance of GoRails site. The contents below are my personal notes for GoRails - Episode 113.
hash = { a: 1, b: 2, c: 3, d: 4 }
#=> {:a=>1, :b=>2, :c=>3, :d=>4}
hash.slice(:a)
#=> {:a=>1}
hash
#=> {:a=>1, :b=>2, :c=>3, :d=>4}
hash.slice(:a, :b)
#=> {:a=>1, :b=>2}
hash
#=> {:a=>1, :b=>2, :c=>3, :d=>4}
hash = { a: 1, b: 2, c: 3, d: 4 }
#=> {:a=>1, :b=>2, :c=>3, :d=>4}
hash.slice!(:a, :b)
#=> {:c=>3, :d=>4}
hash
#=> {:a=>1, :b=>2}
hash = { a: 1, b: 2, c: 3, d: 4 }
#=> {:a=>1, :b=>2, :c=>3, :d=>4}
hash.except(:a)
#=> {:b=>2, :c=>3, :d=>4}
hash
#=> {:a=>1, :b=>2, :c=>3, :d=>4}
hash.except(:a, :b)
#=> {:c=>3, :d=>4}
hash
#=> {:a=>1, :b=>2, :c=>3, :d=>4}
hash = { a: 1, b: 2, c: 3, d: 4 }
#=> {:a=>1, :b=>2, :c=>3, :d=>4}
hash.except!(:a)
#=> {:b=>2, :c=>3, :d=>4}
hash
#=> {:b=>2, :c=>3, :d=>4}
hash = { "a" => 100, "b" => 200 }
#=> {"a"=>100, "b"=>200}
hash.fetch("a")
#=> 100
hash.fetch("z")
# KeyError: key not found: "z"
hash.fetch("z", 0)
#=> 0
hash.fetch("z") { 0 }
#=> 0
hash.fetch("z") { |el| "#{el} not found" }
#=> "z not found"
hash = { "a" => 100, "b" => 200 }
#=> {"a"=>100, "b"=>200}
hash.delete("a")
#=> 100
hash.delete("z")
#=> nil
hash.delete("z"){ [] }
#=> []
hash.delete("z"){ |el| "#{el} not found" }
#=> "z not found"