DEV Community

[Comment from a deleted post]
Collapse
 
valeth profile image
Valeth • Edited

In general pass-by-value is just creating a copy of a value and passing it to a function.
You can kinda "simulate" this behavior by using the Object#dup method.

h = {}

def fun(value)
  puts value.object_id
end

fun(h) # => 47450799554260
fun(h.dup) # => 47450799938380

Just keep in mind that dup is just a shallow copy.