fork download
  1. #!/usr/bin/env ruby
  2.  
  3. def is_ruby_pass_by_value?(foo)
  4. foo << <<-HERE
  5. More precisely, it is call-by-object-sharing!
  6. Call-by-object-sharing is a special case of pass-by-value,
  7. where the value is always an immutable pointer to a (potentially mutable) value.
  8. HERE
  9. foo = 'No, Ruby is pass-by-reference.'
  10. return
  11. end
  12.  
  13. bar = ['Yes, of course, Ruby *is* pass-by-value!']
  14.  
  15. is_ruby_pass_by_value?(bar)
  16.  
  17. puts bar
  18. # Yes, of course, Ruby *is* pass-by-value!,
  19. # More precisely, it is call-by-object-sharing!
Success #stdin #stdout 0.02s 9704KB
stdin
Standard input is empty
stdout
Yes, of course, Ruby *is* pass-by-value!
    More precisely, it is call-by-object-sharing!
    Call-by-object-sharing is a special case of pass-by-value, 
    where the value is always an immutable pointer to a (potentially mutable) value.