Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

ruby hash merge

h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 254, "c" => 300 }
h1.merge(h2)   #=> {"a"=>100, "b"=>254, "c"=>300}
h1.merge(h2){|key, oldval, newval| newval - oldval}
               #=> {"a"=>100, "b"=>54,  "c"=>300}
h1             #=> {"a"=>100, "b"=>200}
Comment

ruby hash merge vs merge!

h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 254, "c" => 300 }
h1.merge!(h2)   #=> {"a"=>100, "b"=>254, "c"=>300}
h1              #=> {"a"=>100, "b"=>254, "c"=>300}

h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 254, "c" => 300 }
h1.merge!(h2) { |key, v1, v2| v1 }
                #=> {"a"=>100, "b"=>200, "c"=>300}
h1              #=> {"a"=>100, "b"=>200, "c"=>300}
Comment

PREVIOUS NEXT
Code Example
Ruby :: ruby create a copy of variable 
Ruby :: compiler version at runtime 
Ruby :: rails time format iso8601 
Ruby :: does destroy retrurn in ruby 
Ruby :: model with array rails 
Ruby :: rails ngrok blocked host 
R :: add a vertical line in ggplot 
R :: r list files in directory 
R :: ggplot increase label font size 
R :: R p value star 
R :: reverse row order dataframe R 
R :: r optim 
R :: r set dataframe column names 
R :: how to find the R packages and versions 
R :: how to read a vector input in r 
R :: r dplyr add total row 
R :: calculate correlation in r 
R :: convert a matrix to a vector in r 
R :: disable the y axis in plot r 
R :: r remove insignificant coefficient in output 
R :: extract residual from lm in r 
R :: turn a numeric dataframe to binary in r 
R :: How to extract NA´s from a column? in R 
R :: bioFabric r 
R :: list variables r 
R :: extract rse from lm in r 
R :: timestamp conversion from excel R 
R :: r count rows dataframe 
Rust :: rust get items in a list with index and value 
Rust :: bevy input 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =