? are you talking about ruby here? Structs are definitively passed by reference.
Person = Struct.new(:name,:age,:friends) {
def inspect() to_s end
def to_s() "Person[#{name},#{age},#{friends}]" end
}
def methIn(person)
person.age=50
end
bob = Person["Bob",14,[]]
methIn(bob)
puts bob #prints Person[Bob,50,[]]
If they were passed by value then methIn would only be altering its local copy.
I do not think that anything at all is passed by value in ruby.
ok then... I'm interested in the gritty details of circular equality in ruby.
I also wrote on reddit (reddit.com/r/ruby/comments/syemrs/...) searching for a better answer, and I'm getting some, but I'm still confused.
You can also take a look at the way we are probably going to do it in Crystal (similar to Ruby, but you don't need to understand C): github.com/crystal-lang/crystal/is...
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
? are you talking about ruby here? Structs are definitively passed by reference.
If they were passed by value then methIn would only be altering its local copy.
I do not think that anything at all is passed by value in ruby.
Sorry! I meant in Crystal.
ok then... I'm interested in the gritty details of circular equality in ruby.
I also wrote on reddit (reddit.com/r/ruby/comments/syemrs/...) searching for a better answer, and I'm getting some, but I'm still confused.
The way it works is:
What happens if these objects are compared in other threads at the same time? Well, the global table keeps these pairs per thread!
At least that's how it will work in Crystal (supporting recursive
to_s
is done with a similar algorithm.)If that default equality isn't a good default, you can always override
==
in Ruby and Crystal.You can also take a look at the way we are probably going to do it in Crystal (similar to Ruby, but you don't need to understand C): github.com/crystal-lang/crystal/is...